#include "commmsg.h"
#include "../mainctrl.h"
#include "../cmd/dataprepare.h"
#include "cmdact.h"
#include "../act/CActCfg.h"
#include "../act/CMagicDoorMgr.h"
#include "../act/CPyramidMgr.h"
#include "../act/CDaySignMgr.h"
#include "../act/CDayWishMgr.h"
#include "../act/CLoginRewardMgr.h"

CT_REGISTER_ASYNCCMD(ID_MAIN_ACT_OPT, CCmdActOpt);
int CCmdActOpt::Do(void* pData)
{
    //解析消息
    CCmdPBDoParam* pstParam = (CCmdPBDoParam*) pData;
    pstMainCtrl = (CMainCtrl*) pstParam->m_pMain;

    if (pstParam->m_pstMsgHead->msgid() != ID_MAIN_ACT_OPT ||
        pstParam->m_pstMsgHead->msgtype() != CSMsgDef::EMT_REQUEST)
    {
        CT_ERROR(("Cmd Stat Err Cmd=%d CmdID=%d Tpye=%d",
            ID_MAIN_ACT_OPT,
            pstParam->m_pstMsgHead->msgid(),
            pstParam->m_pstMsgHead->msgtype()));
        return Done(RET_SYS_ERROR);
    }

    stMsgHead = *(pstParam->m_pstMsgHead);
    stEnpHead = *(pstParam->m_pstEnpHead);
    int iRet = pstMainCtrl->DecodePBMsg(stReq, pstParam);
    if (iRet)
    {
        return AnsClients(iRet);
    }
    //消息解析结束

    //检查登录
    _uiGID = stReq.gid();
    iRet = pstMainCtrl->CheckLogin(_uiGID, stEnpHead);
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    LogicDo(RET_OK);
    return RET_OK;
}

int CCmdActOpt::LogicDo(int iRet)
{
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    PREPARE_PLAYER_BASE_INFO(this, _uiGID);
    ASSERT_PLAYER_PREPARED(_uiGID);

    PREPARE_PLAYER_DETAIL_INFO(this, _uiGID);
    ASSERT_PLAYER_DETAIL_PREPARED(_uiGID);

    PREPARE_PLAYER_DETAIL_INFO(this, _uiGID);

    int iIndex = pstMainCtrl->m_stPlayerBaseInfoHash.HashFind(_uiGID);
    if (iIndex < 0)
	{
        CT_ERROR(("no base data user(%u)", _uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
	}
	CPlayerBaseInfo& stPlayerBase = pstMainCtrl->m_stPlayerBaseInfoHash[iIndex];

    if (stPlayerBase._ucIsInited != 1)
    {
        return AnsClients(ERROR_NOT_INITED);
    }

    iIndex = pstMainCtrl->m_stPlayerDetailInfoHash.HashFind(_uiGID);
    if (iIndex < 0)
	{
        CT_ERROR(("no detail data user(%u)", _uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
	}
	CPlayerDetailInfo& stPlayerDetail =
        pstMainCtrl->m_stPlayerDetailInfoHash[iIndex];

    stTips.Clear();//必须清理一下

    switch (stReq.opt())
    {
    case CActMgr::CMD_ACT_OPT_SUB_GET_ACT_LIST: //获取全量活动列表 会随命令立即刷出
        {
            pstMainCtrl->m_stActMgr.GetActList(stPlayerBase, stPlayerDetail,
                stTips);
        }
        break;
    default:
        iRet = ERROR_MAIN_SUB_CMD;
    }
    
    return AnsClients(iRet);
}

int CCmdActOpt::AnsClients(int iRet)
{
    stMsgHead.set_msgret(iRet);

    if (iRet != RET_OK)
    {
        pstMainCtrl->ReturnMsgHead(stMsgHead, stEnpHead);
        return Done(iRet);
    }

    pstMainCtrl->NotifyOnlineUser(_uiGID, ID_MAIN_TIPS, stTips, true);

    return Done(iRet);
}

/////////////////////怪物攻城/////////////////////////////////////////////////////

CT_REGISTER_ASYNCCMD(ID_MAIN_ENEMY_ATK_CITY, CCmdEnemyAtkCity);
int CCmdEnemyAtkCity::Do(void* pData)
{
    //解析消息
    CCmdPBDoParam* pstParam = (CCmdPBDoParam*) pData;
    pstMainCtrl = (CMainCtrl*) pstParam->m_pMain;

    if (pstParam->m_pstMsgHead->msgid() != ID_MAIN_ENEMY_ATK_CITY ||
        pstParam->m_pstMsgHead->msgtype() != CSMsgDef::EMT_REQUEST)
    {
        CT_ERROR(("Cmd Stat Err Cmd=%d CmdID=%d Tpye=%d",
            ID_MAIN_ENEMY_ATK_CITY,
            pstParam->m_pstMsgHead->msgid(),
            pstParam->m_pstMsgHead->msgtype()));
        return Done(RET_SYS_ERROR);
    }

    stMsgHead = *(pstParam->m_pstMsgHead);
    stEnpHead = *(pstParam->m_pstEnpHead);
    int iRet = pstMainCtrl->DecodePBMsg(stReq, pstParam);
    if (iRet)
    {
        return AnsClients(iRet);
    }
    //消息解析结束

    //检查登录
    uiGID = stReq.gid();
    iRet = pstMainCtrl->CheckLogin(uiGID, stEnpHead);
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    LogicDo(RET_OK);
    return RET_OK;
}

int CCmdEnemyAtkCity::LogicDo(int iRet)
{
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    PREPARE_PLAYER_BASE_INFO(this, uiGID);
    PREPARE_PLAYER_DETAIL_INFO(this, uiGID);
    PREPARE_PLAYER_ONLINE_DATA(this, uiGID);
    PREPARE_PLAYER_DETAIL_EX1_INFO(this, uiGID);
    ASSERT_PLAYER_DETAIL_EX1_INFO(uiGID);

    int iIndex = 0;
    iIndex = pstMainCtrl->m_stPlayerBaseInfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("gid = %u", uiGID));
        return AnsClients(RET_SYS_ERROR);
    }
    CPlayerBaseInfo& stPlayerBaseInfo = pstMainCtrl->m_stPlayerBaseInfoHash[iIndex];

    if (stPlayerBaseInfo._ucIsInited != 1)
    {
        return AnsClients(ERROR_NOT_INITED);
    }

    iIndex = pstMainCtrl->m_stPlayerDetailInfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("gid = %u", uiGID));
        return AnsClients(RET_SYS_ERROR);
    }
    CPlayerDetailInfo& stPlayerDetailInfo = pstMainCtrl->m_stPlayerDetailInfoHash[iIndex];

    iIndex = pstMainCtrl->m_stPlayerDetailEx1InfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("get user detail ex1 info error, uid = %u", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerDetailInfoEx1& stPlayerDetailEx1Info = pstMainCtrl->m_stPlayerDetailEx1InfoHash[iIndex];

    iIndex = pstMainCtrl->m_stPlayerOnlineDataHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("gid = %u", uiGID));
        return AnsClients(RET_SYS_ERROR);
    }
    CPlayerOnlineData& stPlayerOnlineData = pstMainCtrl->m_stPlayerOnlineDataHash[iIndex];

    iIndex = pstMainCtrl->FindPlayerCacheData(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("gid = %u", uiGID));
        return AnsClients(RET_SYS_ERROR);
    }
    CPlayerCacheData& stPlayerCacheData = pstMainCtrl->m_stPlayerCacheDataHash[iIndex];
    CEnemyAtkCityRoleHP& stEnemyAtkCityRoleHP = stPlayerCacheData._stEnemyAtkCityRoleHP;
    CEnemyAtkCityRoleData& stEnemyAtkCityRole = stPlayerCacheData._stEnemyAtkCityRole;
    stEnemyAtkCityRole._uiGID = uiGID;

    bool bNeedSaveDetailInfo = false;
    bool bNeedSaveBaseInfo = false;
    stAns.set_opt(stReq.opt());

    switch (stReq.opt())
    {
    case 1:    //获取战场信息
        {
            iRet = pstMainCtrl->m_stEnemyAtkCityMgr.GetBattleAllStat(stAns);

            if (iRet == RET_OK)
            {
                stAns.set_next_can_battle_time(pstMainCtrl->m_iNow >= stPlayerCacheData._stEnemyAtkCityRole._iNextCanFightTime ? 
                                                    0 : stPlayerCacheData._stEnemyAtkCityRole._iNextCanFightTime);
                stAns.set_revive_price(stPlayerCacheData._stEnemyAtkCityRole.GetRevivePrice(pstMainCtrl->m_iNow));

                CTSizeString<50> szTemp;
                szTemp.Set("%lld", stPlayerCacheData._stEnemyAtkCityRole.GetAtkData(pstMainCtrl->m_stEnemyAtkCityMgr._iBeginTime));
                stAns.set_atk_data(szTemp());
            }
        }
        break;
    case 2:   //打怪
        {
            CDropItem stDropItem;
            int iLeftHP = 0;
            int iKillHP = 0;
            iRet = pstMainCtrl->m_stEnemyAtkCityMgr.AtkEnemy(stReq.enemy_pos(), stEnemyAtkCityRole,
                                            stEnemyAtkCityRoleHP,
                                            stPlayerBaseInfo, stPlayerDetailInfo, stPlayerOnlineData,
                                            (*stAns.mutable_battle_result()), stDropItem, iLeftHP, iKillHP);

            if (RET_OK == iRet)
            {
                stAns.set_enemy_pos(stReq.enemy_pos());
                stAns.set_next_can_battle_time(stPlayerCacheData._stEnemyAtkCityRole._iNextCanFightTime);
                stAns.set_enemy_left_blood(iLeftHP);
                stAns.set_kill_hp(iKillHP);
                CTSizeString<50> szTemp;
                szTemp.Set("%lld", stPlayerCacheData._stEnemyAtkCityRole.GetAtkData(pstMainCtrl->m_stEnemyAtkCityMgr._iBeginTime));
                stAns.set_atk_data(szTemp());

                //显示给前台
                stDropItem.GetPBMsg(uiGID, *(stAns.mutable_atk_bonus()));

                //物品掉落
                stDropItem.SetOssModule(OSS_MODULE_ENMCITY);
                pstMainCtrl->m_stItemMgr.DropItemEx(NULL, uiGID, stDropItem);

                //保存数据
                stPlayerDetailInfo._stEnemyAtkCityRoleData = stPlayerCacheData._stEnemyAtkCityRole;
                bNeedSaveDetailInfo = true;

                //触发任务
                CMainCtrl::m_pstMain->m_stDailyTaskMgr.TriggerTaskFinish(stPlayerOnlineData._stUserDailyTask, DAILY_TASK_ID_28);

                //新手目标
                pstMainCtrl->m_stNewbieTaskMgr.Trigger(stPlayerDetailEx1Info._stNewbieTaskUserData, uiGID, NEWBIE_TASK_COND_12, 1);
            }
        }
        break;
    case 3: //获取当前怪物信息
        {
            pstMainCtrl->m_stEnemyAtkCityMgr.GetBattleChange(stAns);
        }
        break;
    case 6: //个人排行榜
        {
            pstMainCtrl->m_stEnemyAtkCityMgr.GetRoleRank(stAns);
        }
        break;
    case 7: //学院排行榜
        {
            pstMainCtrl->m_stEnemyAtkCityMgr.GetAcaRank(stAns);
        }
        break;
    case 8: //购买复活
        {
            if (stEnemyAtkCityRole._iNextCanFightTime <= pstMainCtrl->m_iNow)
            {
                return AnsClients(ERROR_ENEMY_ATK_CITY_NOT_IN_DIED_CD);
            }
            

            if (stEnemyAtkCityRole._iNextCanFightTime > pstMainCtrl->m_iNow)
            {
                int iPrice = stEnemyAtkCityRole.GetRevivePrice(pstMainCtrl->m_iNow);

                iRet = pstMainCtrl->m_stItemMgr.SubGold(stPlayerBaseInfo, OSS_MONEY_MODULE_34, iPrice);
                if (iRet)
                {
                    return AnsClients(iRet);
                }
                stEnemyAtkCityRole.BuyRevive(pstMainCtrl->m_iNow);
                stEnemyAtkCityRole._iNextCanFightTime = pstMainCtrl->m_iNow;
                stEnemyAtkCityRole._iLastFightTime = pstMainCtrl->m_iNow - MAX_ENEMY_ATK_CITY_FIGHT_COOL_DOWN; //清除冷却时间

                stPlayerDetailInfo._stEnemyAtkCityRoleData = stPlayerCacheData._stEnemyAtkCityRole;
                bNeedSaveDetailInfo = true;
                bNeedSaveBaseInfo = true;
            }

            stAns.set_revive_price(stPlayerCacheData._stEnemyAtkCityRole.GetRevivePrice(pstMainCtrl->m_iNow));

            pstMainCtrl->m_stNotifyMgr.Notify(uiGID, NOTIFY_USER_MONEY);

            //复活广播
            PBMsgHead stMsgHead;
            stMsgHead.set_time(CMainCtrl::m_pstMain->m_iNow);
            stMsgHead.set_msgid(ID_MAIN_ENEMY_ATK_CITY);
            stMsgHead.set_msgret(0);
            stMsgHead.set_msgtype(CSMsgDef::EMT_ANSWER);

            MsgAnsEnemyAtkCity stBroadAns;
            stBroadAns.set_opt(9);
            stBroadAns.set_dest_gid(uiGID);

            CMainCtrl::m_pstMain->m_stEncodeBuf.Clear();
            CMainCtrl::m_pstMain->EncodePBMsg(stMsgHead, CMainCtrl::m_pstMain->m_stEncodeBuf);
            CMainCtrl::m_pstMain->EncodePBMsg(stBroadAns, CMainCtrl::m_pstMain->m_stEncodeBuf);

            CSingleMapView::MAP_VIEW_NOTIFY_USERS_ARRAY astMapUsers;
            CMainCtrl::m_pstMain->m_stMapViews.GetMapUsers(MAX_ENEMY_ATK_CITY_MAP_ID, uiGID, astMapUsers);

            for (int i = 0; i < astMapUsers.Size(); ++i)
            {
                CMainCtrl::m_pstMain->NotifyOnlineUser(astMapUsers[i], CMainCtrl::m_pstMain->m_stEncodeBuf);
            }
        }
        break;
    case 11: //购买祝福
        {
            iRet = pstMainCtrl->m_stEnemyAtkCityMgr.BuyBless(stPlayerCacheData, stPlayerBaseInfo);

            if (RET_OK == iRet)
            {
                bNeedSaveBaseInfo = true;
            }
        }
        break;
    default:
        return AnsClients(RET_SYS_ERROR);
    }

    //保存数据
    if (bNeedSaveDetailInfo)
    {
        CVarObjectKey stKey;
        stKey.m_chDataType = DT_PLAYER_DETAIL_INFO;
        stKey.m_u64ID = stPlayerDetailInfo._uiGID;
        CMainCtrl::m_pstMain->UpdateData(stKey, stPlayerDetailInfo, VOP_UPDATE);
    }

    if (bNeedSaveBaseInfo)
    {
        CVarObjectKey stKey;
        stKey.m_chDataType = DT_PLAYER_BASE_INFO;
        stKey.m_u64ID = stPlayerBaseInfo._uiGID;
        CMainCtrl::m_pstMain->UpdateData(stKey, stPlayerBaseInfo, VOP_UPDATE);
    }


    return AnsClients(iRet);
}

int CCmdEnemyAtkCity::AnsClients(int iRet)
{
    stMsgHead.set_msgret(RET_OK);
    stMsgHead.set_msgtype(CSMsgDef::EMT_ANSWER);

    stAns.set_ret(iRet);
    stAns.set_opt(stReq.opt());
    pstMainCtrl->m_stEncodeBuf.Clear();
    pstMainCtrl->EncodePBMsg(stMsgHead, pstMainCtrl->m_stEncodeBuf);
    pstMainCtrl->EncodePBMsg(stAns, pstMainCtrl->m_stEncodeBuf);
    if (pstMainCtrl->AnswerToClient(stEnpHead, pstMainCtrl->m_stEncodeBuf, true))
    {
        CT_WARNING((""));
        return Done(RET_SYS_ERROR);
    }

    return Done(iRet);
}

//////////////////////Magic Door////////////////////////////////////////////////////

CT_REGISTER_ASYNCCMD(ID_MAIN_MAGIC_DOOR, CCmdMagicDoor);
int CCmdMagicDoor::Do(void* pData)
{
    CT_ASSERT(pData);

    //解析消息
    CCmdPBDoParam* pstParam = (CCmdPBDoParam*) pData;
    pstMainCtrl = (CMainCtrl*) pstParam->m_pMain;

    if (pstParam->m_pstMsgHead->msgid() != ID_MAIN_MAGIC_DOOR ||
        pstParam->m_pstMsgHead->msgtype() != CSMsgDef::EMT_REQUEST)
    {
        CT_ERROR(("Cmd Stat Err Cmd=%d CmdID=%d Tpye=%d",
            ID_MAIN_MAGIC_DOOR,
            pstParam->m_pstMsgHead->msgid(),
            pstParam->m_pstMsgHead->msgtype()));
        return Done(RET_SYS_ERROR);
    }

    stMsgHead = *(pstParam->m_pstMsgHead);
    stEnpHead = *(pstParam->m_pstEnpHead);
    int iRet = pstMainCtrl->DecodePBMsg(stReq, pstParam);
    if (iRet)
    {
        return AnsClients(iRet);
    }
    //消息解析结束

    chSubCmd = stReq.req_type();
    uiGID = stReq.gid();

    //检查登录
    iRet = pstMainCtrl->CheckLogin(uiGID, stEnpHead);
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    stAns.set_gid((int)uiGID);
    stAns.set_req_type(chSubCmd);

    LogicDo(RET_OK);
    return RET_OK;
}

int CCmdMagicDoor::LogicDo(int iRet)
{
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    int iIndex = 0;

    PREPARE_PLAYER_BASE_INFO(this, uiGID); //精力
    ASSERT_PLAYER_PREPARED(uiGID);

    PREPARE_PLAYER_DETAIL_INFO(this, uiGID); //用户个人家族数据
    ASSERT_PLAYER_DETAIL_PREPARED(uiGID);

    PREPARE_PLAYER_SNS_DETAIL_INFO(this, uiGID); //个人家族贡献度
    ASSERT_PLAYER_SNS_DETAIL_PREPARED(uiGID);

    PREPARE_PLAYER_DETAIL_EX1_INFO(this, uiGID);
    ASSERT_PLAYER_DETAIL_EX1_INFO(uiGID);

    PREPARE_PLAYER_ONLINE_DATA(this, uiGID);

    iIndex = pstMainCtrl->m_stPlayerBaseInfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no base data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerBaseInfo& stPlayerBase = pstMainCtrl->m_stPlayerBaseInfoHash[iIndex];

    if (stPlayerBase._ucIsInited != 1)
    {
        return AnsClients(ERROR_NOT_INITED);
    }

    iIndex = pstMainCtrl->m_stPlayerDetailInfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no detail data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerDetailInfo& stPlayerDetail =
        pstMainCtrl->m_stPlayerDetailInfoHash[iIndex];

    iIndex = pstMainCtrl->m_stPlayerDetailEx1InfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("get user detail ex1 info error, uid = %u", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerDetailInfoEx1& stPlayerDetailEx1Info = pstMainCtrl->m_stPlayerDetailEx1InfoHash[iIndex];

    iIndex = pstMainCtrl->m_stPlayerSnsDetailInfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no sns detail data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerSnsDetailInfo& stPlayerSnsDetail =
        pstMainCtrl->m_stPlayerSnsDetailInfoHash[iIndex];

    iIndex = pstMainCtrl->m_stPlayerOnlineDataHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no online data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerOnlineData& stPlayerOnline =
        pstMainCtrl->m_stPlayerOnlineDataHash[iIndex];

    iIndex = pstMainCtrl->FindPlayerCacheData(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no cache data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerCacheData& stPlayerCache =
        pstMainCtrl->m_stPlayerCacheDataHash[iIndex];

	switch (chSubCmd)
	{
    case CMagicDoorMgr::CMD_MAGIC_DOOR_SUB_GET_INFO:
        {
            iRet = pstMainCtrl->m_stMagicDoorMgr.GetMagicDoorInfo(
                stPlayerDetail, stAns);
        }
        break;
    case CMagicDoorMgr::CMD_MAGIC_DOOR_SUB_PAY:
        {
            iRet = pstMainCtrl->m_stMagicDoorMgr.PayContribute(stPlayerBase,
                stPlayerDetail, stPlayerSnsDetail, stPlayerOnline, stAns);
            if (!iRet)
            {
                pstMainCtrl->m_stDailyTaskMgr.TriggerTaskFinish(
                    stPlayerOnline._stUserDailyTask, DAILY_TASK_ID_19);

                //新手目标
                pstMainCtrl->m_stNewbieTaskMgr.Trigger(stPlayerDetailEx1Info._stNewbieTaskUserData, uiGID, NEWBIE_TASK_COND_10, 1);
            }
        }
        break;
    case CMagicDoorMgr::CMD_MAGIC_DOOR_SUB_GET_RANK:
        {
            iRet = pstMainCtrl->m_stMagicDoorMgr.GetPayContributeRank(
                stPlayerDetail, stAns);
        }
        break;
    case CMagicDoorMgr::CMD_MAGIC_DOOR_SUB_CLEAR_CD:
        break;
    case CMagicDoorMgr::CMD_MAGIC_DOOR_SUB_OPEN_DOOR:
        {
            iRet = pstMainCtrl->m_stMagicDoorMgr.MagicDoorOpen(stPlayerBase,
                stPlayerDetail);
        }
        break;
    case CMagicDoorMgr::CMD_MAGIC_DOOR_SUB_GET_MONSTER:
        {
            iRet = pstMainCtrl->m_stMagicDoorMgr.GetMagicDoorMonsterInfo(
                stPlayerDetail, stAns);
        }
        break;
    case CMagicDoorMgr::CMD_MAGIC_DOOR_SUB_BATTLE:
        {
            iRet = pstMainCtrl->m_stMagicDoorMgr.GetMagicDoorBattleCamera(
                stPlayerBase, stPlayerDetail, stPlayerOnline, stPlayerCache,
                stReq, stAns);
        }
        break;
    case CMagicDoorMgr::CMD_MAGIC_DOOR_SUB_NOTIFY_MAGIC_INFO:
        {
            CMagicDoorMonGroup& stMagicMonGroup =
                pstMainCtrl->m_stMagicDoorMgr.GetMagicDoorMonGroup();
            if (stMagicMonGroup.GetMapID() == stPlayerOnline._uiNowMapID)
            {
                stAns.Clear();
                stAns.set_gid(uiGID);
                stAns.set_req_type(CMagicDoorMgr::CMD_MAGIC_DOOR_SUB_GET_INFO);
                pstMainCtrl->m_stMagicDoorMgr.GetMagicDoorInfo(
                    stPlayerDetail, stAns);

                pstMainCtrl->NotifyOnlineUser(uiGID, ID_MAIN_MAGIC_DOOR, stAns,
                    false);
            }
            return Done(RET_OK);
        }
        break;
    case CMagicDoorMgr::CMD_MAGIC_DOOR_SUB_NOTIFY_MONSTER_INFO:
        {
            CMagicDoorMonGroup& stMagicMonGroup =
                pstMainCtrl->m_stMagicDoorMgr.GetMagicDoorMonGroup();
            if (stMagicMonGroup.GetMapID() == stPlayerOnline._uiNowMapID)
            {
                stAns.Clear();
                stAns.set_gid(uiGID);
                stAns.set_req_type(
                    CMagicDoorMgr::CMD_MAGIC_DOOR_SUB_GET_MONSTER);
                pstMainCtrl->m_stMagicDoorMgr.GetMagicDoorMonsterInfo(
                    stPlayerDetail, stAns);

                pstMainCtrl->NotifyOnlineUser(uiGID, ID_MAIN_MAGIC_DOOR, stAns,
                    false);
            }
            return Done(RET_OK);
        }
        break;
	default:
		iRet = ERROR_MAIN_SUB_CMD;
		break;
	}

    if (iRet)
    {
        CT_TRACE(("user(gid=%u) deal magic door op(sub=%d) error(%d)",
                   uiGID,chSubCmd,iRet));
        return AnsClients(iRet);
    }

	if (chSubCmd == CMagicDoorMgr::CMD_MAGIC_DOOR_SUB_PAY)
	{
    	//保存数据 base info
    	CVarObjectKey stKey;
    	stKey.m_chDataType = DT_PLAYER_BASE_INFO;
    	stKey.m_u64ID = uiGID;
    	pstMainCtrl->UpdateData(stKey, stPlayerBase, VOP_UPDATE);
	}

	if (chSubCmd == CMagicDoorMgr::CMD_MAGIC_DOOR_SUB_PAY)
	{
    	//保存数据 detail info
    	CVarObjectKey stKey;
    	stKey.m_chDataType = DT_PLAYER_DETAIL_INFO;
    	stKey.m_u64ID = uiGID;
    	pstMainCtrl->UpdateData(stKey, stPlayerDetail, VOP_UPDATE);
	}

	if (chSubCmd == CMagicDoorMgr::CMD_MAGIC_DOOR_SUB_PAY)
	{
    	//保存数据 sns detail info
    	CVarObjectKey stKey;
    	stKey.m_chDataType = DT_PLAYER_SNS_DETAIL_INFO;
    	stKey.m_u64ID = uiGID;
    	pstMainCtrl->UpdateData(stKey, stPlayerSnsDetail, VOP_UPDATE);
	}

	if (chSubCmd == CMagicDoorMgr::CMD_MAGIC_DOOR_SUB_PAY ||
        chSubCmd == CMagicDoorMgr::CMD_MAGIC_DOOR_SUB_OPEN_DOOR ||
        chSubCmd == CMagicDoorMgr::CMD_MAGIC_DOOR_SUB_BATTLE)
	{
        //更新家族数据至数据库
        pstMainCtrl->m_stClanMgr.UpdateToDB(
            stPlayerDetail._stUserClan._uiClanId);
    }

    return AnsClients(RET_OK);
}

int CCmdMagicDoor::AnsClients(int iRet)
{
    stMsgHead.set_msgret(iRet);
    stMsgHead.set_msgtype(CSMsgDef::EMT_ANSWER);

    if (iRet != RET_OK)
    {
        pstMainCtrl->ReturnMsgHead(stMsgHead, stEnpHead);
        return Done(iRet);
    }

    pstMainCtrl->m_stEncodeBuf.Clear();
    pstMainCtrl->EncodePBMsg(stMsgHead, pstMainCtrl->m_stEncodeBuf);
    pstMainCtrl->EncodePBMsg(stAns, pstMainCtrl->m_stEncodeBuf);
    if (pstMainCtrl->AnswerToClient(stEnpHead, pstMainCtrl->m_stEncodeBuf,
            true))
    {
        CT_WARNING((""));
        return Done(RET_SYS_ERROR);
    }

	if (chSubCmd == CMagicDoorMgr::CMD_MAGIC_DOOR_SUB_PAY)
	{
        //推送角色信息 主要是贡献度和精力
        pstMainCtrl->m_stNotifyMgr.Notify(uiGID, NOTIFY_ROLE_INFO);
        pstMainCtrl->FlushSendCache();
	}

    return Done(iRet);
}

//////////////////////Family Dice////////////////////////////////////////////////////

CT_REGISTER_ASYNCCMD(ID_MAIN_FAMILY_DICE, CCmdFamilyDice);
int CCmdFamilyDice::Do(void* pData)
{
    //解析消息
    CCmdPBDoParam* pstParam = (CCmdPBDoParam*) pData;
    pstMainCtrl = (CMainCtrl*) pstParam->m_pMain;

    if (pstParam->m_pstMsgHead->msgid() != ID_MAIN_FAMILY_DICE||
        pstParam->m_pstMsgHead->msgtype() != CSMsgDef::EMT_REQUEST)
    {
        CT_ERROR(("Cmd Stat Err Cmd=%d CmdID=%d Tpye=%d",
            ID_MAIN_FAMILY_DICE,
            pstParam->m_pstMsgHead->msgid(),
            pstParam->m_pstMsgHead->msgtype()));
        return Done(RET_SYS_ERROR);
    }

    stMsgHead = *(pstParam->m_pstMsgHead);
    stEnpHead = *(pstParam->m_pstEnpHead);
    int iRet = pstMainCtrl->DecodePBMsg(stReq, pstParam);
    if (iRet)
    {
        return AnsClients(iRet);
    }
    //消息解析结束

    //检查登录
    uiGID = stReq.gid();
    iRet = pstMainCtrl->CheckLogin(uiGID, stEnpHead);
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    LogicDo(RET_OK);
    return RET_OK;
}

int CCmdFamilyDice::LogicDo(int iRet)
{
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    if (!pstMainCtrl->m_stFamilyDiceMgr.IsClanUser(uiGID))
    {
        return AnsClients(ERROR_CLAN_NOT_EXIST);
    }

    PREPARE_PLAYER_BASE_INFO(this, uiGID); //用户等级
    PREPARE_PLAYER_DETAIL_INFO(this, uiGID); //用户个人家族闯关信息    
    PREPARE_PLAYER_ONLINE_DATA(this, uiGID);

    int iIndex = 0;
    iIndex = pstMainCtrl->m_stPlayerBaseInfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("gid = %u", uiGID));
        return AnsClients(RET_SYS_ERROR);
    }
    CPlayerBaseInfo& stPlayerBaseInfo = pstMainCtrl->m_stPlayerBaseInfoHash[iIndex];

    if (stPlayerBaseInfo._ucIsInited != 1)
    {
        return AnsClients(ERROR_NOT_INITED);
    }

    iIndex = pstMainCtrl->m_stPlayerDetailInfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("gid = %u", uiGID));
        return AnsClients(RET_SYS_ERROR);
    }
    CPlayerDetailInfo& stPlayerDetailInfo = pstMainCtrl->m_stPlayerDetailInfoHash[iIndex];
        
    iIndex = pstMainCtrl->m_stPlayerOnlineDataHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("get user online info error, uid = %u", uiGID));
        return AnsClients(RET_SYS_ERROR);
    }
    CPlayerOnlineData& stPlayerOnlineData = pstMainCtrl->m_stPlayerOnlineDataHash[iIndex];

    //初始化本周最好记录
    pstMainCtrl->m_stFamilyDiceMgr.InitDiceBestRecord (stPlayerDetailInfo, pstMainCtrl->m_iNow);

    stAns.set_req_type(stReq.req_type());
    stAns.set_gid(stReq.gid());

    iRet = pstMainCtrl->m_stFamilyDiceMgr.DoReq(stReq, stAns);

    if (RET_OK == iRet)
    {
        if (CONST_DICE_SHAKE_COMMON == stReq.req_type()
            || CONST_DICE_SHAKE_BUY == stReq.req_type())
        {
            //触发任务
            pstMainCtrl->m_stDailyTaskMgr.TriggerTaskFinish(stPlayerOnlineData._stUserDailyTask, DAILY_TASK_ID_21);
            pstMainCtrl->m_stTaskMgr.TriggerDoSomeOpt(stPlayerOnlineData._stUserTask, TASK_OPT_ID_126, 1);
        }
    }
    

    return AnsClients(iRet);
}

int CCmdFamilyDice::AnsClients(int iRet)
{
    stMsgHead.set_msgret(iRet);
    stMsgHead.set_msgtype(CSMsgDef::EMT_ANSWER);

    if (iRet != RET_OK)
    {
        pstMainCtrl->ReturnMsgHead(stMsgHead, stEnpHead);
        return Done(iRet);
    }

    stAns.set_ret(iRet);

    pstMainCtrl->m_stEncodeBuf.Clear();
    pstMainCtrl->EncodePBMsg(stMsgHead, pstMainCtrl->m_stEncodeBuf);
    pstMainCtrl->EncodePBMsg(stAns, pstMainCtrl->m_stEncodeBuf);
    if (pstMainCtrl->AnswerToClient(stEnpHead, pstMainCtrl->m_stEncodeBuf, true))
    {
        CT_WARNING((""));
        return Done(RET_SYS_ERROR);
    }

    return Done(iRet);
}

//////////////////////Auction////////////////////////////////////////////////////

CT_REGISTER_ASYNCCMD(ID_MAIN_AUCTION, CCmdAuction);
int CCmdAuction::Do(void* pData)
{
    //解析消息
    CCmdPBDoParam* pstParam = (CCmdPBDoParam*) pData;
    pstMainCtrl = (CMainCtrl*) pstParam->m_pMain;

    if (pstParam->m_pstMsgHead->msgid() != ID_MAIN_AUCTION||
        pstParam->m_pstMsgHead->msgtype() != CSMsgDef::EMT_REQUEST)
    {
        CT_ERROR(("Cmd Stat Err Cmd=%d CmdID=%d Tpye=%d",
            ID_MAIN_AUCTION,
            pstParam->m_pstMsgHead->msgid(),
            pstParam->m_pstMsgHead->msgtype()));
        return Done(RET_SYS_ERROR);
    }

    stMsgHead = *(pstParam->m_pstMsgHead);
    stEnpHead = *(pstParam->m_pstEnpHead);
    int iRet = pstMainCtrl->DecodePBMsg(stReq, pstParam);
    if (iRet)
    {
        return AnsClients(iRet);
    }
    //消息解析结束

    //检查登录
    uiGID = stReq.gid();
    iRet = pstMainCtrl->CheckLogin(uiGID, stEnpHead);
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    LogicDo(RET_OK);
    return RET_OK;
}

int CCmdAuction::LogicDo(int iRet)
{
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    PREPARE_PLAYER_BASE_INFO(this, uiGID);

    int iIndex = 0;
    iIndex = pstMainCtrl->m_stPlayerBaseInfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("gid = %u", uiGID));
        return AnsClients(RET_SYS_ERROR);
    }
    CPlayerBaseInfo& stPlayerBaseInfo = pstMainCtrl->m_stPlayerBaseInfoHash[iIndex];

    if (stPlayerBaseInfo._ucIsInited != 1)
    {
        return AnsClients(ERROR_NOT_INITED);
    }

    iIndex = pstMainCtrl->m_stPlayerOnlineDataHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no online data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerOnlineData& stPlayerOnline =
        pstMainCtrl->m_stPlayerOnlineDataHash[iIndex];

    //检查系统是否开启
    if (!CMainCtrl::m_pstMain->m_stCommConfigLoader.IsOpen(SYS_OPEN_COND_ID_36, stPlayerBaseInfo, stPlayerOnline))
    {
        return AnsClients(ERROR_SYS_NOT_OPEN);
    }

    iRet = pstMainCtrl->m_stAuctionMgr.DoReq(stReq, stAns);
    return AnsClients(iRet);
}

int CCmdAuction::AnsClients(int iRet)
{
    stMsgHead.set_msgret(iRet);
    stMsgHead.set_msgtype(CSMsgDef::EMT_ANSWER);

    if (iRet != RET_OK)
    {
        pstMainCtrl->ReturnMsgHead(stMsgHead, stEnpHead);
        return Done(iRet);
    }

    stAns.set_opt(stReq.opt());
    pstMainCtrl->m_stEncodeBuf.Clear();
    pstMainCtrl->EncodePBMsg(stMsgHead, pstMainCtrl->m_stEncodeBuf);
    pstMainCtrl->EncodePBMsg(stAns, pstMainCtrl->m_stEncodeBuf);
    if (pstMainCtrl->AnswerToClient(stEnpHead, pstMainCtrl->m_stEncodeBuf, true))
    {
        CT_WARNING((""));
        return Done(RET_SYS_ERROR);
    }

    return Done(iRet);
}

//////////////////////Wish////////////////////////////////////////////////////

CT_REGISTER_ASYNCCMD(ID_MAIN_WISH, CCmdWish);
int CCmdWish::Do(void* pData)
{
    //解析消息
    CCmdPBDoParam* pstParam = (CCmdPBDoParam*) pData;
    pstMainCtrl = (CMainCtrl*) pstParam->m_pMain;

    if (pstParam->m_pstMsgHead->msgid() != ID_MAIN_WISH ||
        pstParam->m_pstMsgHead->msgtype() != CSMsgDef::EMT_REQUEST)
    {
        CT_ERROR(("Cmd Stat Err Cmd=%d CmdID=%d Tpye=%d",
            ID_MAIN_WISH,
            pstParam->m_pstMsgHead->msgid(),
            pstParam->m_pstMsgHead->msgtype()));
        return Done(RET_SYS_ERROR);
    }

    stMsgHead = *(pstParam->m_pstMsgHead);
    stEnpHead = *(pstParam->m_pstEnpHead);
    int iRet = pstMainCtrl->DecodePBMsg(stReq, pstParam);
    if (iRet)
    {
        return AnsClients(iRet);
    }
    //消息解析结束


    //检查登录
    uiGID = stReq.gid();
    iRet = pstMainCtrl->CheckLogin(uiGID, stEnpHead);
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    LogicDo(RET_OK);
    return RET_OK;
}

int CCmdWish::LogicDo(int iRet)
{
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    PREPARE_PLAYER_BASE_INFO(this, uiGID); //用户等级
    PREPARE_PLAYER_DETAIL_INFO(this, uiGID); //用户等级
    PREPARE_PLAYER_ONLINE_DATA(this, uiGID);

    int iIndex = 0;
    iIndex = pstMainCtrl->m_stPlayerBaseInfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("gid = %u", uiGID));
        return AnsClients(RET_SYS_ERROR);
    }
    CPlayerBaseInfo& stPlayerBaseInfo = pstMainCtrl->m_stPlayerBaseInfoHash[iIndex];

    if (stPlayerBaseInfo._ucIsInited != 1)
    {
        return AnsClients(ERROR_NOT_INITED);
    }

    iIndex = pstMainCtrl->m_stPlayerDetailInfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("gid = %u", uiGID));
        return AnsClients(RET_SYS_ERROR);
    }

    iIndex = pstMainCtrl->m_stPlayerOnlineDataHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        return AnsClients(RET_NO_USER);
    }
    CPlayerOnlineData& stPlayerOnlineData = pstMainCtrl->m_stPlayerOnlineDataHash[iIndex];

    //检查系统是否开启
    if (!pstMainCtrl->m_stCommConfigLoader.IsOpen(SYS_OPEN_COND_ID_29, stPlayerBaseInfo, stPlayerOnlineData))
    {
        return AnsClients(ERROR_SYS_NOT_OPEN);
    }

    stAns.set_req_type(stReq.req_type());
    stAns.set_gid(stReq.gid());

    iRet = pstMainCtrl->m_stWishMgr.DoReq(stReq, stAns);

    return AnsClients(iRet);
}

int CCmdWish::AnsClients(int iRet)
{
    stMsgHead.set_msgret(iRet);
    stMsgHead.set_msgtype(CSMsgDef::EMT_ANSWER);

    if (iRet != RET_OK)
    {
        pstMainCtrl->ReturnMsgHead(stMsgHead, stEnpHead);
        return Done(iRet);
    }

    stAns.set_ret(iRet);

    pstMainCtrl->m_stEncodeBuf.Clear();
    pstMainCtrl->EncodePBMsg(stMsgHead, pstMainCtrl->m_stEncodeBuf);
    pstMainCtrl->EncodePBMsg(stAns, pstMainCtrl->m_stEncodeBuf);
    if (pstMainCtrl->AnswerToClient(stEnpHead, pstMainCtrl->m_stEncodeBuf, true))
    {
        CT_WARNING(("AnswertoClient fail:CCmdWish::AnsClients"));
        return Done(RET_SYS_ERROR);
    }

    return Done(iRet);
}

//////////////////////精彩活动////////////////////////////////////////////////////

CT_REGISTER_ASYNCCMD(ID_MAIN_SPLENDID_ACT, CCmdSplendidAct);
int CCmdSplendidAct::Do(void* pData)
{
    //解析消息
    CCmdPBDoParam* pstParam = (CCmdPBDoParam*) pData;
    pstMainCtrl = (CMainCtrl*) pstParam->m_pMain;

    if (pstParam->m_pstMsgHead->msgid() != ID_MAIN_SPLENDID_ACT ||
        pstParam->m_pstMsgHead->msgtype() != CSMsgDef::EMT_REQUEST)
    {
        CT_ERROR(("Cmd Stat Err Cmd=%d CmdID=%d Tpye=%d",
            ID_MAIN_SPLENDID_ACT,
            pstParam->m_pstMsgHead->msgid(),
            pstParam->m_pstMsgHead->msgtype()));
        return Done(RET_SYS_ERROR);
    }

    stMsgHead = *(pstParam->m_pstMsgHead);
    stEnpHead = *(pstParam->m_pstEnpHead);
    int iRet = pstMainCtrl->DecodePBMsg(stReq, pstParam);
    if (iRet)
    {
        return AnsClients(iRet);
    }
    //消息解析结束

    //检查登录
    uiGID = stReq.gid();
    iRet = pstMainCtrl->CheckLogin(uiGID, stEnpHead);
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    LogicDo(RET_OK);
    return RET_OK;
}

int CCmdSplendidAct::LogicDo(int iRet)
{
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    PREPARE_PLAYER_BASE_INFO(this, uiGID);
    PREPARE_PLAYER_DETAIL_INFO(this, uiGID);
    PREPARE_PLAYER_DETAIL_EX1_INFO(this, uiGID);
    PREPARE_PLAYER_ONLINE_DATA(this, uiGID);

    int iIndex = 0;
    iIndex = pstMainCtrl->m_stPlayerBaseInfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("gid = %u", uiGID));
        return AnsClients(RET_SYS_ERROR);
    }
    CPlayerBaseInfo& stPlayerBaseInfo = pstMainCtrl->m_stPlayerBaseInfoHash[iIndex];

    if (stPlayerBaseInfo._ucIsInited != 1)
    {
        return AnsClients(ERROR_NOT_INITED);
    }

    iIndex = pstMainCtrl->m_stPlayerDetailInfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("gid = %u", uiGID));
        return AnsClients(RET_SYS_ERROR);
    }
    CPlayerDetailInfo& stPlayerDetailInfo = pstMainCtrl->m_stPlayerDetailInfoHash[iIndex];

    iIndex = pstMainCtrl->m_stPlayerDetailEx1InfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("gid = %u", uiGID));
        return AnsClients(RET_SYS_ERROR);
    }

    iIndex = pstMainCtrl->m_stPlayerOnlineDataHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("gid = %u", uiGID));
        return AnsClients(RET_SYS_ERROR);
    }
    CPlayerOnlineData& stPlayerOnlineData = pstMainCtrl->m_stPlayerOnlineDataHash[iIndex];

    stAns.set_opt(stReq.opt());

    switch (stReq.opt())
    {
    case 1: //获取活动列表
        {
            pstMainCtrl->m_stActMgr.GetSplendidActListInfo(
                stPlayerDetailInfo._stSplendidAct, uiGID, stAns);
        }
        break;
    case 2:
        {
            iRet = pstMainCtrl->m_stActMgr.GetSplendidActDetailInfo(
                stPlayerDetailInfo._stSplendidAct, uiGID, stReq.act_id(),
                stAns);
        }
        break;
    case 3:
        {
            iRet = pstMainCtrl->m_stActMgr.GetSplendidActBonus(
                stPlayerDetailInfo._stSplendidAct, uiGID, stReq.act_id(),
                stReq.bonus_pos(), stAns);

            if (RET_OK == iRet)
            {
                //跑马灯
                MsgTips stTips;

                switch (stReq.act_id())
                {
                case SPLENDID_ACT_ID_1:
                    stTips.set_type(1048);
                    stTips.add_tip_argument(stPlayerBaseInfo._sRoleName());
                    break;
                case SPLENDID_ACT_ID_2:
                    stTips.set_type(1049);
                    stTips.add_tip_argument(stPlayerBaseInfo._sRoleName());
                    break;
                case SPLENDID_ACT_ID_3:
                    stTips.set_type(1050);
                    stTips.add_tip_argument(stPlayerBaseInfo._sRoleName());
                    stTips.add_tip_argument(stPlayerOnlineData._stUserPet.GetPetName());
                    break;
                case SPLENDID_ACT_ID_4:
                    stTips.set_type(1051);
                    stTips.add_tip_argument(stPlayerBaseInfo._sRoleName());
                    stTips.add_tip_argument(stPlayerOnlineData._stUserPet.GetPetName());
                    break;
                case SPLENDID_ACT_ID_5:
                    stTips.set_type(1052);
                    stTips.add_tip_argument(stPlayerBaseInfo._sRoleName());
                    stTips.add_tip_argument(stPlayerOnlineData._stUserPet.GetPetName());
                    break;
                case SPLENDID_ACT_ID_6:
                    stTips.set_type(1053);
                    stTips.add_tip_argument(stPlayerBaseInfo._sRoleName());
                    break;
                case SPLENDID_ACT_ID_9:
                    {
                        stTips.set_type(1055 + stReq.bonus_pos());
                        stTips.add_tip_argument(stPlayerBaseInfo._sRoleName());
                        //CT_ERROR(("GetSplendidActBonus: %u, %d, %d", 
                                //uiGID, stPlayerDetailInfo._stSplendidAct._iEnemyAtkCityKillEnemyCount, stReq.bonus_pos()));
                    }
                    break;
                default:
                    break;
                }

                if (stTips.type() != 0)
                {
                    CMainCtrl::m_pstMain->SendOnlineTips(stTips);
                }
            }
        }
        break;
    default:
        iRet = RET_SYS_ERROR;
        break;
    }

    return AnsClients(iRet);
}

int CCmdSplendidAct::AnsClients(int iRet)
{
    stMsgHead.set_msgret(iRet);
    stMsgHead.set_msgtype(CSMsgDef::EMT_ANSWER);

    if (iRet != RET_OK)
    {
        pstMainCtrl->ReturnMsgHead(stMsgHead, stEnpHead);
        return Done(iRet);
    }

    pstMainCtrl->m_stEncodeBuf.Clear();
    pstMainCtrl->EncodePBMsg(stMsgHead, pstMainCtrl->m_stEncodeBuf);
    pstMainCtrl->EncodePBMsg(stAns, pstMainCtrl->m_stEncodeBuf);
    if (pstMainCtrl->AnswerToClient(stEnpHead, pstMainCtrl->m_stEncodeBuf, true))
    {
        CT_WARNING(("AnswertoClient fail:CCmdSplendidAct::AnsClients"));
        return Done(RET_SYS_ERROR);
    }

    return Done(iRet);
}

//////////////////////金字塔活动////////////////////////////////////////////////////

CT_REGISTER_ASYNCCMD(ID_MAIN_PYRAMID_ACT, CCmdPyramidAct);
int CCmdPyramidAct::Do(void* pData)
{
    //解析消息
    CCmdPBDoParam* pstParam = (CCmdPBDoParam*) pData;
    pstMainCtrl = (CMainCtrl*) pstParam->m_pMain;

    if (pstParam->m_pstMsgHead->msgid() != ID_MAIN_PYRAMID_ACT ||
        pstParam->m_pstMsgHead->msgtype() != CSMsgDef::EMT_REQUEST)
    {
        CT_ERROR(("Cmd Stat Err Cmd=%d CmdID=%d Tpye=%d",
            ID_MAIN_PYRAMID_ACT,
            pstParam->m_pstMsgHead->msgid(),
            pstParam->m_pstMsgHead->msgtype()));
        return Done(RET_SYS_ERROR);
    }

    stMsgHead = *(pstParam->m_pstMsgHead);
    stEnpHead = *(pstParam->m_pstEnpHead);
    int iRet = pstMainCtrl->DecodePBMsg(stReq, pstParam);
    if (iRet)
    {
        return AnsClients(iRet);
    }
    //消息解析结束

    //检查登录
    uiGID = stReq.gid();
    iRet = pstMainCtrl->CheckLogin(uiGID, stEnpHead);
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    LogicDo(RET_OK);
    return RET_OK;
}

int CCmdPyramidAct::LogicDo(int iRet)
{
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    PREPARE_PLAYER_BASE_INFO(this, uiGID);
    PREPARE_PLAYER_DETAIL_INFO(this, uiGID);
    PREPARE_PLAYER_ONLINE_DATA(this, uiGID);

    int iIndex = 0;
    iIndex = pstMainCtrl->m_stPlayerBaseInfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("gid = %u", uiGID));
        return AnsClients(RET_SYS_ERROR);
    }
    CPlayerBaseInfo& stPlayerBaseInfo = pstMainCtrl->m_stPlayerBaseInfoHash[iIndex];

    if (stPlayerBaseInfo._ucIsInited != 1)
    {
        return AnsClients(ERROR_NOT_INITED);
    }

    iIndex = pstMainCtrl->m_stPlayerDetailInfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("gid = %u", uiGID));
        return AnsClients(RET_SYS_ERROR);
    }
    CPlayerDetailInfo& stPlayerDetailInfo = pstMainCtrl->m_stPlayerDetailInfoHash[iIndex];
    CPyramidActData& stPyramidAct = stPlayerDetailInfo._stPyramidAct;

    iIndex = pstMainCtrl->m_stPlayerOnlineDataHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("gid = %u", uiGID));
        return AnsClients(RET_SYS_ERROR);
    }
    CPlayerOnlineData& stPlayerOnlineData = pstMainCtrl->m_stPlayerOnlineDataHash[iIndex];

    stAns.set_opt(stReq.opt());
    bool bSaveDetailInfo = false;
    bool bSaveBaseInfo = false;

    switch (stReq.opt())
    {
    case 1: //查询列表
        {
            pstMainCtrl->m_stPyramidMgr.GetListInfo(stPyramidAct, stAns);
        }
        break;
    case 2: //查详情
        {
            pstMainCtrl->m_stPyramidMgr.GetDetailInfo(stPyramidAct, stReq.pyramid_id(), *stAns.mutable_detail_info());
        }
        break;
    case 4: //攻击（前往）
        {
            iRet = pstMainCtrl->m_stPyramidMgr.GoToPos(stPyramidAct, stReq.pyramid_id(), (stReq.is_left_door() == 1), 
                    stPlayerBaseInfo, stPlayerDetailInfo, stPlayerOnlineData, stAns);
            
            if (RET_OK == iRet)
            {
                bSaveDetailInfo = true;

                MsgBattleResult* pstMsgBattleResult = stAns.mutable_battle_result();
                if (pstMsgBattleResult && stReq.has_ext_info())
                {
                    (*pstMsgBattleResult->mutable_battle_ext_info()) = stReq.ext_info();
                }
            }
            
        }
        break;
    case 5: //重置
        {
            int iMaxCanResetCount = 0;
            iRet = pstMainCtrl->m_stVipMgr.GetVipDestNum(stPlayerBaseInfo._chVipLevel, VIP_MODULE_ID_26, iMaxCanResetCount);
            if (RET_OK != iRet)
            {
                return AnsClients(iRet);
            }

            iRet = pstMainCtrl->m_stPyramidMgr.ResetPyramid(stPyramidAct, stReq.pyramid_id(), iMaxCanResetCount, stPlayerBaseInfo, stAns);
        
            if (RET_OK == iRet)
            {
                bSaveBaseInfo = true;
                bSaveDetailInfo = true;

                pstMainCtrl->m_stNotifyMgr.Notify(uiGID, NOTIFY_USER_MONEY);
            }
        }
        break;
    case 6: //领奖
        {
            iRet = pstMainCtrl->m_stPyramidMgr.GetBonus(stPyramidAct, stReq.pyramid_id(), stReq.bonus_type(), stPlayerOnlineData, stAns);

            if (RET_OK != iRet)
            {
                bSaveDetailInfo = true;
            }
        }
        break;
    default:
        iRet = RET_SYS_ERROR;
        break;
    }

    if (bSaveDetailInfo)
    {
        CVarObjectKey stKey;
        stKey.m_chDataType = DT_PLAYER_DETAIL_INFO;
        stKey.m_u64ID = stPlayerDetailInfo._uiGID;
        CMainCtrl::m_pstMain->UpdateData(stKey, stPlayerDetailInfo, VOP_UPDATE);
    }

    if (bSaveBaseInfo)
    {
        CVarObjectKey stKey;
        stKey.m_chDataType = DT_PLAYER_BASE_INFO;
        stKey.m_u64ID = stPlayerBaseInfo._uiGID;
        CMainCtrl::m_pstMain->UpdateData(stKey, stPlayerBaseInfo, VOP_UPDATE);
    }
    

    return AnsClients(iRet);
}

int CCmdPyramidAct::AnsClients(int iRet)
{
    stMsgHead.set_msgret(iRet);
    stMsgHead.set_msgtype(CSMsgDef::EMT_ANSWER);

    if (iRet != RET_OK)
    {
        pstMainCtrl->ReturnMsgHead(stMsgHead, stEnpHead);
        return Done(iRet);
    }

    pstMainCtrl->m_stEncodeBuf.Clear();
    pstMainCtrl->EncodePBMsg(stMsgHead, pstMainCtrl->m_stEncodeBuf);
    pstMainCtrl->EncodePBMsg(stAns, pstMainCtrl->m_stEncodeBuf);
    if (pstMainCtrl->AnswerToClient(stEnpHead, pstMainCtrl->m_stEncodeBuf, true))
    {
        CT_WARNING(("AnswertoClient fail:CCmdSplendidAct::AnsClients"));
        return Done(RET_SYS_ERROR);
    }

    return Done(iRet);
}

//////////////////////登录送符石////////////////////////////////////////////////////
CT_REGISTER_ASYNCCMD(ID_MAIN_LOGIN_GOLD, CCmdLoginGold);
int CCmdLoginGold::Do(void* pData)
{
    //解析消息
    CCmdPBDoParam* pstParam = (CCmdPBDoParam*) pData;
    pstMainCtrl = (CMainCtrl*) pstParam->m_pMain;

    if (pstParam->m_pstMsgHead->msgid() != ID_MAIN_LOGIN_GOLD ||
        pstParam->m_pstMsgHead->msgtype() != CSMsgDef::EMT_REQUEST)
    {
        CT_ERROR(("Cmd Stat Err Cmd=%d CmdID=%d Tpye=%d",
            ID_MAIN_LOGIN_GOLD,
            pstParam->m_pstMsgHead->msgid(),
            pstParam->m_pstMsgHead->msgtype()));
        return Done(RET_SYS_ERROR);
    }

    stMsgHead = *(pstParam->m_pstMsgHead);
    stEnpHead = *(pstParam->m_pstEnpHead);
    int iRet = pstMainCtrl->DecodePBMsg(stReq, pstParam);
    if (iRet)
    {
        return AnsClients(iRet);
    }
    //消息解析结束

    //检查登录
    _uiGID = stReq.gid();
    iRet = pstMainCtrl->CheckLogin(_uiGID, stEnpHead);
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    LogicDo(RET_OK);
    return RET_OK;
}

int CCmdLoginGold::LogicDo(int iRet)
{
    if (iRet)
    {
        return AnsClients(iRet);
    }

    PREPARE_PLAYER_BASE_INFO(this, _uiGID);
    PREPARE_PLAYER_DETAIL_EX1_INFO(this, _uiGID);
    PREPARE_PLAYER_ONLINE_DATA(this, _uiGID);
    PREPARE_PLAYER_SNS_DETAIL_INFO(this, _uiGID);

    int iIndex = pstMainCtrl->m_stPlayerBaseInfoHash.HashFind(_uiGID);
    if (iIndex < 0)
    {
        return AnsClients(RET_NO_USER);
    }
    CPlayerBaseInfo & stPlayerBaseInfo = pstMainCtrl->m_stPlayerBaseInfoHash[iIndex];

    if (stPlayerBaseInfo._ucIsInited != 1)
    {
        return AnsClients(ERROR_NOT_INITED);
    }

    iIndex = pstMainCtrl->m_stPlayerDetailEx1InfoHash.HashFind(_uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("gid = %u", _uiGID));
        return AnsClients(RET_SYS_ERROR);
    }
    CPlayerDetailInfoEx1 & stPlayerDetailInfoEx1 = pstMainCtrl->m_stPlayerDetailEx1InfoHash[iIndex];

    iIndex = pstMainCtrl->m_stPlayerOnlineDataHash.HashFind(_uiGID);
    if (iIndex < 0)
    {
        return AnsClients(RET_NO_USER);
    }
    CPlayerOnlineData & stPlayerOnlineData = pstMainCtrl->m_stPlayerOnlineDataHash[iIndex];

    if (!pstMainCtrl->m_stCommConfigLoader.IsOpen(SYS_OPEN_COND_ID_42, stPlayerBaseInfo, stPlayerOnlineData))
    {
        return AnsClients(ERROR_SYS_NOT_OPEN);
    }

    iIndex = pstMainCtrl->m_stPlayerSnsDetailInfoHash.HashFind(_uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("gid = %u", _uiGID));
        return AnsClients(RET_SYS_ERROR);
    }    
    int iTodayOnlineSecs = pstMainCtrl->m_stRoleMgr.GetTodayOnlineSeconds(pstMainCtrl->m_stPlayerSnsDetailInfoHash[iIndex], pstMainCtrl->m_iNow);

    //有可能跨多天,更新登陆天数
    pstMainCtrl->m_stRoleMgr.UpdateLoginDays(stPlayerDetailInfoEx1, pstMainCtrl->m_iNow);

    unsigned char ucOpt = stReq.opt();
    bool bNeedSaveDetail = false;    
    
    if (1 == ucOpt)         //1:获取当前信息
    {          
        iRet = GetGoldAvailInfo (stPlayerDetailInfoEx1, pstMainCtrl->m_iNow, iTodayOnlineSecs, stAns);
        if (iRet)
        {
            return AnsClients(iRet);
        }
    }
    else if (2 == ucOpt)    //2: 领取符石.
    {
        if (stPlayerDetailInfoEx1._iLoginDayCnt > 3)
        {
            return AnsClients(ERROR_LOGIN_GOLD_TIME);
        }
        
        int iStatus = stPlayerDetailInfoEx1._stLoginGold.GetDayStatus(stPlayerDetailInfoEx1._iLoginDayCnt);        
        if (3 == iStatus)
        {
            return AnsClients(ERROR_LOGIN_GOLD_TODAY);
        }

        int iHours = CTTimeUtils::GetHourFromTs(pstMainCtrl->m_iNow); 

        //领过一次, 检查在线时间，是否达到领取符石的条件
        if ((1 == iStatus) && (iTodayOnlineSecs < 3600) && (iHours != 23))
        {
            return AnsClients(ERROR_LOGIN_GOLD_CDTIME);
        }
                
        int iCanGetNums = stPlayerDetailInfoEx1._stLoginGold.GetGoldCount(stPlayerDetailInfoEx1._iLoginDayCnt, iTodayOnlineSecs, iHours);

        CDropItem stDropItem;
        stDropItem.DropGold(iCanGetNums);
        stDropItem.SetOssModule(OSS_MODULE_LOGIN_GOLD);

        pstMainCtrl->m_stItemMgr.DropItem(NULL, _uiGID, stDropItem, false);        
        
        bNeedSaveDetail = true;
        stPlayerDetailInfoEx1._stLoginGold.AddGoldNum(stPlayerDetailInfoEx1._iLoginDayCnt, iCanGetNums);        

        CT_TRACE(("%d, %d, %d, %d, %d", _uiGID, pstMainCtrl->m_iNow, iCanGetNums, iTodayOnlineSecs, iStatus));
        
        //获取下次领取的信息
        iRet = GetGoldAvailInfo (stPlayerDetailInfoEx1, pstMainCtrl->m_iNow, iTodayOnlineSecs, stAns);
        if (iRet)
        {
            return AnsClients(iRet);
        }

        stAns.set_get_cnt(iCanGetNums);
    }
    else
    {
        return AnsClients(ERROR_LOGIN_GOLD_OPT);
    }

    if (bNeedSaveDetail)
    {
        CVarObjectKey stKey;
        stKey.m_chDataType = DT_PLAYER_DETAIL_EX1_INFO;
        stKey.m_u64ID = stPlayerDetailInfoEx1._uiGID;
        pstMainCtrl->UpdateData(stKey, stPlayerDetailInfoEx1, VOP_UPDATE);
    }

    return AnsClients(RET_OK);
}

int CCmdLoginGold::AnsClients(int iRet)
{
    stMsgHead.set_msgret(iRet);
    stMsgHead.set_msgtype(CSMsgDef::EMT_ANSWER);

    if (iRet != RET_OK)
    {
        pstMainCtrl->ReturnMsgHead(stMsgHead, stEnpHead);
        return Done(iRet);
    }

    stAns.set_opt(stReq.opt());
    pstMainCtrl->m_stEncodeBuf.Clear();
    pstMainCtrl->EncodePBMsg(stMsgHead, pstMainCtrl->m_stEncodeBuf);
    pstMainCtrl->EncodePBMsg(stAns, pstMainCtrl->m_stEncodeBuf);
    if (pstMainCtrl->AnswerToClient(stEnpHead, pstMainCtrl->m_stEncodeBuf, true))
    {
        CT_WARNING((""));
        return Done(RET_SYS_ERROR);
    }

    return Done(iRet);
}

int CCmdLoginGold::GetGoldAvailInfo (CPlayerDetailInfoEx1 & stDetail, int iNowTime, int iTodayOnlineSecs, MsgAnsLoginGold & stAns)
{   
    if (stDetail._iLoginDayCnt < 0)
    {
        stAns.set_day (0);
        return RET_OK;
    }  

    stAns.set_day(stDetail._iLoginDayCnt);

    //设置前几天的领取状态
    for (int i = 1; i < CT_MIN(stDetail._iLoginDayCnt, MAX_LOGIN_GOLD_DAYS); i++)
    {
        stAns.add_prev_status (stDetail._stLoginGold.GetDayStatus(i));
    }

    if (stDetail._iLoginDayCnt <= MAX_LOGIN_GOLD_DAYS)
    {
        int iStatus = stDetail._stLoginGold.GetDayStatus(stDetail._iLoginDayCnt);
        stAns.set_status(iStatus);

        if (3 == iStatus)
        {
            return RET_OK;
        }

        int iHours = CTTimeUtils::GetHourFromTs(pstMainCtrl->m_iNow);
        int iCanGetNums = stDetail._stLoginGold.GetGoldCount(stDetail._iLoginDayCnt, iTodayOnlineSecs, iHours);
        if (1 == iStatus)
        {
            //23点登陆的,直接可以领取. 22点首次登陆的,领取时间统一设置为23点.  其它时间登陆的, 在线满足60分钟后，领取剩余一半的奖励. 
            int i23Time = CTTimeUtils::GetDayBeginSec(iNowTime) + 23 * 3600;
            if (23 == iHours)
            {
                stAns.set_available_time(i23Time);
            }
            else
            {
                int iEstTime = pstMainCtrl->m_iNow + CT_MAX((3600 - iTodayOnlineSecs), 0);           
                stAns.set_available_time(CT_MIN(i23Time, iEstTime));
            }           
        }

        stAns.set_count(iCanGetNums);
    }

    return RET_OK;
}

//////////////////////每日签到活动////////////////////////////////////////////////////
CT_REGISTER_ASYNCCMD(ID_MAIN_DAY_SIGN, CCmdDaySign);
int CCmdDaySign::Do(void* pData)
{
    CT_ASSERT(pData);

    //解析消息
    CCmdPBDoParam* pstParam = (CCmdPBDoParam*) pData;
    pstMainCtrl = (CMainCtrl*) pstParam->m_pMain;

    if (pstParam->m_pstMsgHead->msgid() != ID_MAIN_DAY_SIGN ||
        pstParam->m_pstMsgHead->msgtype() != CSMsgDef::EMT_REQUEST)
    {
        CT_ERROR(("Cmd Stat Err Cmd=%d CmdID=%d Tpye=%d",
            ID_MAIN_DAY_SIGN,
            pstParam->m_pstMsgHead->msgid(),
            pstParam->m_pstMsgHead->msgtype()));
        return Done(RET_SYS_ERROR);
    }

    stMsgHead = *(pstParam->m_pstMsgHead);
    stEnpHead = *(pstParam->m_pstEnpHead);
    int iRet = pstMainCtrl->DecodePBMsg(stReq, pstParam);
    if (iRet)
    {
        return AnsClients(iRet);
    }
    //消息解析结束

    chSubCmd = stReq.req_type();
    uiGID = stReq.gid();

    //检查登录
    iRet = pstMainCtrl->CheckLogin(uiGID, stEnpHead);
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    stAns.set_gid((int)uiGID);
    stAns.set_req_type(chSubCmd);

    LogicDo(RET_OK);
    return RET_OK;
}

int CCmdDaySign::LogicDo(int iRet)
{
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    int iIndex = 0;

    PREPARE_PLAYER_BASE_INFO(this, uiGID);
    ASSERT_PLAYER_PREPARED(uiGID);

    PREPARE_PLAYER_DETAIL_EX1_INFO(this, uiGID);
    ASSERT_PLAYER_DETAIL_EX1_INFO(uiGID);

    PREPARE_PLAYER_ONLINE_DATA(this, uiGID);
    ASSERT_PLAYER_ONLINE_DATA_PREPARED(uiGID);

    iIndex = pstMainCtrl->m_stPlayerBaseInfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no base data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerBaseInfo& stPlayerBase = pstMainCtrl->m_stPlayerBaseInfoHash[iIndex];

    if (stPlayerBase._ucIsInited != 1)
    {
        return AnsClients(ERROR_NOT_INITED);
    }

    iIndex = pstMainCtrl->m_stPlayerDetailEx1InfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no detail ex1 data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerDetailInfoEx1& stPlayerDetailEx1 =
        pstMainCtrl->m_stPlayerDetailEx1InfoHash[iIndex];

    iIndex = pstMainCtrl->m_stPlayerOnlineDataHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no online data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerOnlineData& stPlayerOnline =
        pstMainCtrl->m_stPlayerOnlineDataHash[iIndex];

    //检查系统是否开启
    if (!CMainCtrl::m_pstMain->m_stCommConfigLoader.IsOpen(SYS_OPEN_COND_ID_44,
            stPlayerBase, stPlayerOnline))
    {
        return AnsClients(ERROR_SYS_NOT_OPEN);
    }

	switch (chSubCmd)
	{
    case CDaySignMgr::CMD_DAY_SIGN_SUB_GET_INFO:
        {
            iRet = pstMainCtrl->m_stDaySignMgr.GetDaySignInfo(stPlayerDetailEx1,
                stAns);
        }
        break;
    case CDaySignMgr::CMD_DAY_SIGN_SUB_NOTIFY_INFO:
        {
            stAns.set_req_type(CDaySignMgr::CMD_DAY_SIGN_SUB_GET_INFO);
            pstMainCtrl->m_stDaySignMgr.GetDaySignInfo(stPlayerDetailEx1,
                stAns);
            pstMainCtrl->NotifyOnlineUser(uiGID, ID_MAIN_DAY_SIGN, stAns,
                false);
            return Done(RET_OK);//命令不需要响应包直接Done
        }
        break;
    case CDaySignMgr::CMD_DAY_SIGN_SUB_DAY_SIGN:
        {
            iRet = pstMainCtrl->m_stDaySignMgr.PlayerSign(stPlayerDetailEx1,
                stAns);
        }
        break;
    case CDaySignMgr::CMD_DAY_SIGN_SUB_REPAIR_SIGN:
        {
            iRet = pstMainCtrl->m_stDaySignMgr.PlayerRepairSign(stPlayerBase,
                stPlayerDetailEx1, stAns);
        }
        break;
    case CDaySignMgr::CMD_DAY_SIGN_SUB_CONTINUE_AWARD:
        {
            iRet = pstMainCtrl->m_stDaySignMgr.GetContinueAward(
                stPlayerDetailEx1, stPlayerOnline, stReq, stAns);
        }
        break;
    case CDaySignMgr::CMD_DAY_SIGN_SUB_ACCUMULATIVE_AWARD:
        {
            iRet = pstMainCtrl->m_stDaySignMgr.GetAccumulateAward(
                stPlayerDetailEx1, stPlayerOnline, stReq, stAns);
        }
        break;
	default:
		iRet = ERROR_MAIN_SUB_CMD;
		break;
	}

    if (iRet)
    {
        CT_TRACE(("user(gid=%u) deal day sign op(sub=%d) error(%d)",
            uiGID,chSubCmd,iRet));
        return AnsClients(iRet);
    }

	if (chSubCmd == CDaySignMgr::CMD_DAY_SIGN_SUB_REPAIR_SIGN)
	{
    	//保存数据 base info
    	CVarObjectKey stKey;
    	stKey.m_chDataType = DT_PLAYER_BASE_INFO;
    	stKey.m_u64ID = uiGID;
    	pstMainCtrl->UpdateData(stKey, stPlayerBase, VOP_UPDATE);
	}

	if (chSubCmd == CDaySignMgr::CMD_DAY_SIGN_SUB_DAY_SIGN ||
        chSubCmd == CDaySignMgr::CMD_DAY_SIGN_SUB_REPAIR_SIGN ||
        chSubCmd == CDaySignMgr::CMD_DAY_SIGN_SUB_CONTINUE_AWARD ||
        chSubCmd == CDaySignMgr::CMD_DAY_SIGN_SUB_ACCUMULATIVE_AWARD)
    {
        CVarObjectKey stKey;
        stKey.m_chDataType = DT_PLAYER_DETAIL_EX1_INFO;
        stKey.m_u64ID = stPlayerDetailEx1._uiGID;
        pstMainCtrl->UpdateData(stKey, stPlayerDetailEx1, VOP_UPDATE);
    }

    return AnsClients(RET_OK);
}

int CCmdDaySign::AnsClients(int iRet)
{
    stMsgHead.set_msgret(iRet);
    stMsgHead.set_msgtype(CSMsgDef::EMT_ANSWER);

    if (iRet != RET_OK)
    {
        pstMainCtrl->ReturnMsgHead(stMsgHead, stEnpHead);
        return Done(iRet);
    }

    pstMainCtrl->m_stEncodeBuf.Clear();
    pstMainCtrl->EncodePBMsg(stMsgHead, pstMainCtrl->m_stEncodeBuf);
    pstMainCtrl->EncodePBMsg(stAns, pstMainCtrl->m_stEncodeBuf);
    if (pstMainCtrl->AnswerToClient(stEnpHead, pstMainCtrl->m_stEncodeBuf,
            true))
    {
        CT_WARNING((""));
        return Done(RET_SYS_ERROR);
    }

    return Done(iRet);
}

//////////////////////每日许愿活动////////////////////////////////////////////////////
CT_REGISTER_ASYNCCMD(ID_MAIN_DAY_WISH, CCmdDayWish);
int CCmdDayWish::Do(void* pData)
{
    CT_ASSERT(pData);

    //解析消息
    CCmdPBDoParam* pstParam = (CCmdPBDoParam*) pData;
    pstMainCtrl = (CMainCtrl*) pstParam->m_pMain;

    if (pstParam->m_pstMsgHead->msgid() != ID_MAIN_DAY_WISH ||
        pstParam->m_pstMsgHead->msgtype() != CSMsgDef::EMT_REQUEST)
    {
        CT_ERROR(("Cmd Stat Err Cmd=%d CmdID=%d Tpye=%d",
            ID_MAIN_DAY_SIGN,
            pstParam->m_pstMsgHead->msgid(),
            pstParam->m_pstMsgHead->msgtype()));
        return Done(RET_SYS_ERROR);
    }

    stMsgHead = *(pstParam->m_pstMsgHead);
    stEnpHead = *(pstParam->m_pstEnpHead);
    int iRet = pstMainCtrl->DecodePBMsg(stReq, pstParam);
    if (iRet)
    {
        return AnsClients(iRet);
    }
    //消息解析结束

    chSubCmd = stReq.req_type();
    uiGID = stReq.gid();

    //检查登录
    iRet = pstMainCtrl->CheckLogin(uiGID, stEnpHead);
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    stAns.set_gid((int)uiGID);
    stAns.set_req_type(chSubCmd);

    LogicDo(RET_OK);
    return RET_OK;
}

int CCmdDayWish::LogicDo(int iRet)
{
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    int iIndex = 0;

    PREPARE_PLAYER_BASE_INFO(this, uiGID);
    ASSERT_PLAYER_PREPARED(uiGID);

    PREPARE_PLAYER_DETAIL_EX1_INFO(this, uiGID);
    ASSERT_PLAYER_DETAIL_EX1_INFO(uiGID);

    PREPARE_PLAYER_ONLINE_DATA(this, uiGID);
    ASSERT_PLAYER_ONLINE_DATA_PREPARED(uiGID);

    iIndex = pstMainCtrl->m_stPlayerBaseInfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no base data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerBaseInfo& stPlayerBase = pstMainCtrl->m_stPlayerBaseInfoHash[iIndex];

    if (stPlayerBase._ucIsInited != 1)
    {
        return AnsClients(ERROR_NOT_INITED);
    }

    iIndex = pstMainCtrl->m_stPlayerDetailEx1InfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no detail ex1 data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerDetailInfoEx1& stPlayerDetailEx1 =
        pstMainCtrl->m_stPlayerDetailEx1InfoHash[iIndex];

    iIndex = pstMainCtrl->m_stPlayerOnlineDataHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no online data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerOnlineData& stPlayerOnline =
        pstMainCtrl->m_stPlayerOnlineDataHash[iIndex];

    //检查系统是否开启
    if (!CMainCtrl::m_pstMain->m_stCommConfigLoader.IsOpen(SYS_OPEN_COND_ID_44,
            stPlayerBase, stPlayerOnline))
    {
        return AnsClients(ERROR_SYS_NOT_OPEN);
    }

	switch (chSubCmd)
	{
    case CDayWishMgr::CMD_DAY_WISH_SUB_GET_INFO:
        {
            iRet = pstMainCtrl->m_stDayWishMgr.GetDayWishInfo(stPlayerDetailEx1,
                stAns);
        }
        break;
    case CDayWishMgr::CMD_DAY_WISH_SUB_NOTIFY_INFO:
        {
            stAns.set_req_type(CDayWishMgr::CMD_DAY_WISH_SUB_GET_INFO);
            pstMainCtrl->m_stDayWishMgr.GetDayWishInfo(stPlayerDetailEx1,
                stAns);
            pstMainCtrl->NotifyOnlineUser(uiGID, ID_MAIN_DAY_WISH, stAns,
                false);
            return Done(RET_OK);//命令不需要响应包直接Done
        }
        break;
    case CDayWishMgr::CMD_DAY_WISH_SUB_DAY_WISH:
        {
            iRet = pstMainCtrl->m_stDayWishMgr.PlayerWish(stPlayerDetailEx1,
                stReq, stAns);
        }
        break;
    case CDayWishMgr::CMD_DAY_WISH_SUB_GET_AWARD:
        {
            iRet = pstMainCtrl->m_stDayWishMgr.GetAward(stPlayerDetailEx1,
                stPlayerOnline, stReq, stAns);
        }
        break;
	default:
		iRet = ERROR_MAIN_SUB_CMD;
		break;
	}

    if (iRet)
    {
        CT_TRACE(("user(gid=%u) deal day wish op(sub=%d) error(%d)",
            uiGID,chSubCmd,iRet));
        return AnsClients(iRet);
    }

	if (chSubCmd == CDayWishMgr::CMD_DAY_WISH_SUB_DAY_WISH ||
        chSubCmd == CDayWishMgr::CMD_DAY_WISH_SUB_GET_AWARD)
    {
        CVarObjectKey stKey;
        stKey.m_chDataType = DT_PLAYER_DETAIL_EX1_INFO;
        stKey.m_u64ID = stPlayerDetailEx1._uiGID;
        pstMainCtrl->UpdateData(stKey, stPlayerDetailEx1, VOP_UPDATE);
    }

    return AnsClients(RET_OK);
}

int CCmdDayWish::AnsClients(int iRet)
{
    stMsgHead.set_msgret(iRet);
    stMsgHead.set_msgtype(CSMsgDef::EMT_ANSWER);

    if (iRet != RET_OK)
    {
        pstMainCtrl->ReturnMsgHead(stMsgHead, stEnpHead);
        return Done(iRet);
    }

    pstMainCtrl->m_stEncodeBuf.Clear();
    pstMainCtrl->EncodePBMsg(stMsgHead, pstMainCtrl->m_stEncodeBuf);
    pstMainCtrl->EncodePBMsg(stAns, pstMainCtrl->m_stEncodeBuf);
    if (pstMainCtrl->AnswerToClient(stEnpHead, pstMainCtrl->m_stEncodeBuf,
            true))
    {
        CT_WARNING((""));
        return Done(RET_SYS_ERROR);
    }

    return Done(iRet);
}

//////////////////////新手任务活动////////////////////////////////////////////////////
CT_REGISTER_ASYNCCMD(ID_MAIN_NEWBIE_TASK, CCmdNewbieTask);
int CCmdNewbieTask::Do(void* pData)
{
    CT_ASSERT(pData);

    //解析消息
    CCmdPBDoParam* pstParam = (CCmdPBDoParam*) pData;
    pstMainCtrl = (CMainCtrl*) pstParam->m_pMain;

    if (pstParam->m_pstMsgHead->msgid() != ID_MAIN_NEWBIE_TASK||
        pstParam->m_pstMsgHead->msgtype() != CSMsgDef::EMT_REQUEST)
    {
        CT_ERROR(("Cmd Stat Err Cmd=%d CmdID=%d Tpye=%d",
            ID_MAIN_NEWBIE_TASK,
            pstParam->m_pstMsgHead->msgid(),
            pstParam->m_pstMsgHead->msgtype()));
        return Done(RET_SYS_ERROR);
    }

    stMsgHead = *(pstParam->m_pstMsgHead);
    stEnpHead = *(pstParam->m_pstEnpHead);
    int iRet = pstMainCtrl->DecodePBMsg(stReq, pstParam);
    if (iRet)
    {
        return AnsClients(iRet);
    }
    //消息解析结束

    uiGID = stReq.gid();

    //检查登录
    iRet = pstMainCtrl->CheckLogin(uiGID, stEnpHead);
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    LogicDo(RET_OK);
    return RET_OK;
}

int CCmdNewbieTask::LogicDo(int iRet)
{
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    int iIndex = 0;

    PREPARE_PLAYER_BASE_INFO(this, uiGID);
    ASSERT_PLAYER_PREPARED(uiGID);

    PREPARE_PLAYER_DETAIL_EX1_INFO(this, uiGID);
    ASSERT_PLAYER_DETAIL_EX1_INFO(uiGID);

    PREPARE_PLAYER_ONLINE_DATA(this, uiGID);
    ASSERT_PLAYER_ONLINE_DATA_PREPARED(uiGID);

    iIndex = pstMainCtrl->m_stPlayerBaseInfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no base data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerBaseInfo& stPlayerBase = pstMainCtrl->m_stPlayerBaseInfoHash[iIndex];

    if (stPlayerBase._ucIsInited != 1)
    {
        return AnsClients(ERROR_NOT_INITED);
    }

    iIndex = pstMainCtrl->m_stPlayerDetailEx1InfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no detail ex1 data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerDetailInfoEx1& stPlayerDetailEx1 =
        pstMainCtrl->m_stPlayerDetailEx1InfoHash[iIndex];

    /*
    iIndex = pstMainCtrl->m_stPlayerOnlineDataHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no online data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerOnlineData& stPlayerOnline =
        pstMainCtrl->m_stPlayerOnlineDataHash[iIndex];
    */

    stAns.set_opt(stReq.opt());

    bool bSaveEx1Data = false;

    switch (stReq.opt())
    {
    case 1: //获取数据列表
        {
            pstMainCtrl->m_stNewbieTaskMgr.GetTaskInfo(stPlayerDetailEx1._stNewbieTaskUserData, uiGID, stAns);
        }
        break;
    case 2: //领每日奖励
        {
            iRet = pstMainCtrl->m_stNewbieTaskMgr.GetDayBonus(stPlayerDetailEx1._stNewbieTaskUserData, uiGID, stReq.day(), stAns);
            stAns.set_day(stReq.day());
            stAns.set_task_id(stReq.task_id());
            bSaveEx1Data = true;
        }
        break;
    case 3: //领任务奖励
        {
            iRet = pstMainCtrl->m_stNewbieTaskMgr.GetTaskBonus(stPlayerDetailEx1._stNewbieTaskUserData, uiGID, stReq.task_id(), stAns);
            stAns.set_day(stReq.day());
            stAns.set_task_id(stReq.task_id());
            bSaveEx1Data = true;
        }
        break;
    default:
        iRet = RET_SYS_ERROR;
        break;
    }

    if (bSaveEx1Data)
    {
        CVarObjectKey stKey;
        stKey.m_chDataType = DT_PLAYER_DETAIL_EX1_INFO;
        stKey.m_u64ID = stPlayerDetailEx1._uiGID;
        CMainCtrl::m_pstMain->UpdateData(stKey, stPlayerDetailEx1, VOP_UPDATE);
    }
    
    return AnsClients(iRet);
}

int CCmdNewbieTask::AnsClients(int iRet)
{
    stMsgHead.set_msgret(iRet);
    stMsgHead.set_msgtype(CSMsgDef::EMT_ANSWER);

    if (iRet != RET_OK)
    {
        pstMainCtrl->ReturnMsgHead(stMsgHead, stEnpHead);
        return Done(iRet);
    }

    pstMainCtrl->m_stEncodeBuf.Clear();
    pstMainCtrl->EncodePBMsg(stMsgHead, pstMainCtrl->m_stEncodeBuf);
    pstMainCtrl->EncodePBMsg(stAns, pstMainCtrl->m_stEncodeBuf);
    if (pstMainCtrl->AnswerToClient(stEnpHead, pstMainCtrl->m_stEncodeBuf,
        true))
    {
        CT_WARNING((""));
        return Done(RET_SYS_ERROR);
    }

    return Done(iRet);
}

//////////////////////成长基金////////////////////////////////////////////////////
CT_REGISTER_ASYNCCMD(ID_MAIN_GROW_FUND, CCmdGrowFund);
int CCmdGrowFund::Do(void* pData)
{
    CT_ASSERT(pData);

    //解析消息
    CCmdPBDoParam* pstParam = (CCmdPBDoParam*) pData;
    pstMainCtrl = (CMainCtrl*) pstParam->m_pMain;

    if (pstParam->m_pstMsgHead->msgid() != ID_MAIN_GROW_FUND ||
        pstParam->m_pstMsgHead->msgtype() != CSMsgDef::EMT_REQUEST)
    {
        CT_ERROR(("Cmd Stat Err Cmd=%d CmdID=%d Tpye=%d",
            ID_MAIN_GROW_FUND,
            pstParam->m_pstMsgHead->msgid(),
            pstParam->m_pstMsgHead->msgtype()));
        return Done(RET_SYS_ERROR);
    }

    stMsgHead = *(pstParam->m_pstMsgHead);
    stEnpHead = *(pstParam->m_pstEnpHead);
    int iRet = pstMainCtrl->DecodePBMsg(stReq, pstParam);
    if (iRet)
    {
        return AnsClients(iRet);
    }
    //消息解析结束

    uiGID = stReq.gid();

    //检查登录
    iRet = pstMainCtrl->CheckLogin(uiGID, stEnpHead);
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    LogicDo(RET_OK);
    return RET_OK;
}

int CCmdGrowFund::LogicDo(int iRet)
{
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    int iIndex = 0;

    PREPARE_PLAYER_BASE_INFO(this, uiGID);
    ASSERT_PLAYER_PREPARED(uiGID);

    PREPARE_PLAYER_DETAIL_EX1_INFO(this, uiGID);
    ASSERT_PLAYER_DETAIL_EX1_INFO(uiGID);

    PREPARE_PLAYER_ONLINE_DATA(this, uiGID);

    iIndex = pstMainCtrl->m_stPlayerBaseInfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no base data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerBaseInfo& stPlayerBase = pstMainCtrl->m_stPlayerBaseInfoHash[iIndex];

    if (stPlayerBase._ucIsInited != 1)
    {
        return AnsClients(ERROR_NOT_INITED);
    }

    iIndex = pstMainCtrl->m_stPlayerDetailEx1InfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no detail ex1 data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerDetailInfoEx1& stPlayerDetailEx1 =
        pstMainCtrl->m_stPlayerDetailEx1InfoHash[iIndex];

    iIndex = pstMainCtrl->m_stPlayerOnlineDataHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no online data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerOnlineData& stPlayerOnline =
        pstMainCtrl->m_stPlayerOnlineDataHash[iIndex];

    //检查系统是否开启
    if (!pstMainCtrl->m_stCommConfigLoader.IsOpen(SYS_OPEN_COND_ID_46, stPlayerBase, stPlayerOnline))
    {
        return AnsClients(ERROR_SYS_NOT_OPEN);
    }

    CPayActData& stPayActData = stPlayerDetailEx1._stPayActData;

    bool bNeedSaveEx1Data = false;

    stAns.set_opt(stReq.opt());
    switch (stReq.opt())
    {
    case 1: //查询
        {
            stAns.set_has_buy(stPayActData._ucHasBuyGrowFund);

            if (stPayActData._ucHasBuyGrowFund == 1)    //已经购买
            {
                for (int i = 0; i < MAX_GROW_FUND_TYPE; ++i)
                {
                    stAns.add_has_get(stPayActData.HasGetPayFund(i) ? 1 : 0);
                }
            }
        }
        break;
    case 2: //领取奖励
        {
            if (stPayActData._ucHasBuyGrowFund != 1)
            {
                return AnsClients(ERROR_GROW_FUND_ERROR1);
            }
            
            int iPos = stReq.index() - 1;
            if (iPos < 0 || iPos >= MAX_GROW_FUND_TYPE)
            {
                return AnsClients(RET_SYS_ERROR);
            }
            
            if (stPayActData.HasGetPayFund(iPos))
            {
                return AnsClients(ERROR_GROW_FUND_ERROR2);
            }

            if (!stPayActData.PayFundCheckLevel(stPlayerBase._shLevel, iPos))
            {
                return AnsClients(ERROR_GROW_FUND_ERROR3);
            }
            
            int iGoldCount = stPayActData.PayFundGetGoldCount(iPos);
            stPayActData.SetHasGetPayFund(iPos);

            //物品掉落
            CDropItem stDropItem;
            stDropItem.SetOssModule(OSS_MODULE_GROW_FUND);
            stDropItem.DropGold(iGoldCount);

            pstMainCtrl->m_stItemMgr.DropItem(NULL, uiGID, stDropItem);
            stAns.set_get_gold(iGoldCount);

            for (int i = 0; i < MAX_GROW_FUND_TYPE; ++i)
            {
                stAns.add_has_get(stPayActData.HasGetPayFund(i) ? 1 : 0);
            }

            bNeedSaveEx1Data = true;
            
        }
        break;
    default:
        return AnsClients(RET_SYS_ERROR);
    }

    if (iRet)
    {
        return AnsClients(iRet);
    }

    if (bNeedSaveEx1Data)
    {
        CVarObjectKey stKey;
        stKey.m_chDataType = DT_PLAYER_DETAIL_EX1_INFO;
        stKey.m_u64ID = uiGID;
        pstMainCtrl->UpdateData(stKey, stPlayerDetailEx1, VOP_UPDATE);
    }
    

    return AnsClients(RET_OK);
}

int CCmdGrowFund::AnsClients(int iRet)
{
    stMsgHead.set_msgret(iRet);
    stMsgHead.set_msgtype(CSMsgDef::EMT_ANSWER);

    if (iRet != RET_OK)
    {
        pstMainCtrl->ReturnMsgHead(stMsgHead, stEnpHead);
        return Done(iRet);
    }

    pstMainCtrl->m_stEncodeBuf.Clear();
    pstMainCtrl->EncodePBMsg(stMsgHead, pstMainCtrl->m_stEncodeBuf);
    pstMainCtrl->EncodePBMsg(stAns, pstMainCtrl->m_stEncodeBuf);
    if (pstMainCtrl->AnswerToClient(stEnpHead, pstMainCtrl->m_stEncodeBuf,
        true))
    {
        CT_WARNING((""));
        return Done(RET_SYS_ERROR);
    }

    return Done(iRet);
}

//////////////////////消费返利////////////////////////////////////////////////////
CT_REGISTER_ASYNCCMD(ID_MAIN_PAY_BACK, CCmdPayBack);
int CCmdPayBack::Do(void* pData)
{
    CT_ASSERT(pData);

    //解析消息
    CCmdPBDoParam* pstParam = (CCmdPBDoParam*) pData;
    pstMainCtrl = (CMainCtrl*) pstParam->m_pMain;

    if (pstParam->m_pstMsgHead->msgid() != ID_MAIN_PAY_BACK ||
        pstParam->m_pstMsgHead->msgtype() != CSMsgDef::EMT_REQUEST)
    {
        CT_ERROR(("Cmd Stat Err Cmd=%d CmdID=%d Tpye=%d",
            ID_MAIN_PAY_BACK,
            pstParam->m_pstMsgHead->msgid(),
            pstParam->m_pstMsgHead->msgtype()));
        return Done(RET_SYS_ERROR);
    }

    stMsgHead = *(pstParam->m_pstMsgHead);
    stEnpHead = *(pstParam->m_pstEnpHead);
    int iRet = pstMainCtrl->DecodePBMsg(stReq, pstParam);
    if (iRet)
    {
        return AnsClients(iRet);
    }
    //消息解析结束

    uiGID = stReq.gid();

    //检查登录
    iRet = pstMainCtrl->CheckLogin(uiGID, stEnpHead);
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    LogicDo(RET_OK);
    return RET_OK;
}

int CCmdPayBack::LogicDo(int iRet)
{
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    int iIndex = 0;

    PREPARE_PLAYER_BASE_INFO(this, uiGID);
    ASSERT_PLAYER_PREPARED(uiGID);

    PREPARE_PLAYER_DETAIL_EX1_INFO(this, uiGID);
    ASSERT_PLAYER_DETAIL_EX1_INFO(uiGID);

    PREPARE_PLAYER_ONLINE_DATA(this, uiGID);

    iIndex = pstMainCtrl->m_stPlayerBaseInfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no base data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerBaseInfo& stPlayerBase = pstMainCtrl->m_stPlayerBaseInfoHash[iIndex];

    if (stPlayerBase._ucIsInited != 1)
    {
        return AnsClients(ERROR_NOT_INITED);
    }

    iIndex = pstMainCtrl->m_stPlayerDetailEx1InfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no detail ex1 data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerDetailInfoEx1& stPlayerDetailEx1 =
        pstMainCtrl->m_stPlayerDetailEx1InfoHash[iIndex];

    /*
    iIndex = pstMainCtrl->m_stPlayerOnlineDataHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no online data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerOnlineData& stPlayerOnline =
        pstMainCtrl->m_stPlayerOnlineDataHash[iIndex];
        */

    CPayActData& stPayActData = stPlayerDetailEx1._stPayActData;

    bool bNeedSaveEx1Data = false;

    stAns.set_opt(stReq.opt());
    switch (stReq.opt())
    {
    case 1: //查询
        {
            stAns.set_has_pay(stPayActData._stTodayPayQPoint.Get(pstMainCtrl->m_iNow, 0));
            stAns.set_can_get(stPayActData.GetTomorrowCanGetPayBackGold(stPlayerBase._chVipLevel, pstMainCtrl->m_iNow));
            stAns.set_now_can_get(stPayActData.GetTodayCanGetPayBackGold(stPlayerBase._chVipLevel, pstMainCtrl->m_iNow));
        }
        break;
    case 2: //领取
        {
            int iCanGetGold = stPayActData.GetTodayCanGetPayBackGold(stPlayerBase._chVipLevel, pstMainCtrl->m_iNow);
            if (iCanGetGold <= 0)
            {
                return AnsClients(RET_SYS_ERROR);
            }
            
            stPayActData.SetGetPayBackGold(pstMainCtrl->m_iNow);

            //物品掉落
            CDropItem stDropItem;
            stDropItem.SetOssModule(OSS_MODULE_PAY_BACK);
            stDropItem.DropGold(iCanGetGold);

            pstMainCtrl->m_stItemMgr.DropItem(NULL, uiGID, stDropItem);

            stAns.set_get_gold(iCanGetGold);
            stAns.set_has_pay(stPayActData._stTodayPayQPoint.Get(pstMainCtrl->m_iNow, 0));
            stAns.set_can_get(stPayActData.GetTomorrowCanGetPayBackGold(stPlayerBase._chVipLevel, pstMainCtrl->m_iNow));
            stAns.set_now_can_get(stPayActData.GetTodayCanGetPayBackGold(stPlayerBase._chVipLevel, pstMainCtrl->m_iNow));

            bNeedSaveEx1Data = true;

            //跑马灯
            MsgTips stTips;
            stTips.set_type(1071);
            stTips.add_tip_argument(stPlayerBase._sRoleName());
            stTips.add_tip_argument(CTStringUtils::IntToString(iCanGetGold));
            CMainCtrl::m_pstMain->SendOnlineTips(stTips);	
        }
        break;
    default:
        return AnsClients(RET_SYS_ERROR);
    }

    if (iRet)
    {
        return AnsClients(iRet);
    }

    if (bNeedSaveEx1Data)
    {
        CVarObjectKey stKey;
        stKey.m_chDataType = DT_PLAYER_DETAIL_EX1_INFO;
        stKey.m_u64ID = uiGID;
        pstMainCtrl->UpdateData(stKey, stPlayerDetailEx1, VOP_UPDATE);
    }
    

    return AnsClients(RET_OK);
}

int CCmdPayBack::AnsClients(int iRet)
{
    stMsgHead.set_msgret(iRet);
    stMsgHead.set_msgtype(CSMsgDef::EMT_ANSWER);

    if (iRet != RET_OK)
    {
        pstMainCtrl->ReturnMsgHead(stMsgHead, stEnpHead);
        return Done(iRet);
    }

    pstMainCtrl->m_stEncodeBuf.Clear();
    pstMainCtrl->EncodePBMsg(stMsgHead, pstMainCtrl->m_stEncodeBuf);
    pstMainCtrl->EncodePBMsg(stAns, pstMainCtrl->m_stEncodeBuf);
    if (pstMainCtrl->AnswerToClient(stEnpHead, pstMainCtrl->m_stEncodeBuf,
        true))
    {
        CT_WARNING((""));
        return Done(RET_SYS_ERROR);
    }

    return Done(iRet);
}

//////////////////////宝箱争夺活动////////////////////////////////////////////////////
CT_REGISTER_ASYNCCMD(ID_MAIN_FIGHT_FOR_BOX, CCmdFightForBox);
int CCmdFightForBox::Do(void* pData)
{
    CT_ASSERT(pData);

    //解析消息
    CCmdPBDoParam* pstParam = (CCmdPBDoParam*) pData;
    pstMainCtrl = (CMainCtrl*) pstParam->m_pMain;

    if (pstParam->m_pstMsgHead->msgid() != ID_MAIN_FIGHT_FOR_BOX||
        pstParam->m_pstMsgHead->msgtype() != CSMsgDef::EMT_REQUEST)
    {
        CT_ERROR(("Cmd Stat Err Cmd=%d CmdID=%d Tpye=%d",
            ID_MAIN_FIGHT_FOR_BOX,
            pstParam->m_pstMsgHead->msgid(),
            pstParam->m_pstMsgHead->msgtype()));
        return Done(RET_SYS_ERROR);
    }

    stMsgHead = *(pstParam->m_pstMsgHead);
    stEnpHead = *(pstParam->m_pstEnpHead);
    int iRet = pstMainCtrl->DecodePBMsg(stReq, pstParam);
    if (iRet)
    {
        return AnsClients(iRet);
    }
    //消息解析结束

    uiGID = stReq.gid();

    //检查登录
    iRet = pstMainCtrl->CheckLogin(uiGID, stEnpHead);
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    LogicDo(RET_OK);
    return RET_OK;
}

int CCmdFightForBox::LogicDo(int iRet)
{
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    int iIndex = 0;

    PREPARE_PLAYER_BASE_INFO(this, uiGID);
    ASSERT_PLAYER_PREPARED(uiGID);

    PREPARE_PLAYER_DETAIL_EX1_INFO(this, uiGID);
    ASSERT_PLAYER_DETAIL_EX1_INFO(uiGID);
        
    PREPARE_PLAYER_ONLINE_DATA(this, uiGID);
    ASSERT_PLAYER_ONLINE_DATA_PREPARED(uiGID);    

    iIndex = pstMainCtrl->m_stPlayerBaseInfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no base data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerBaseInfo& stPlayerBase = pstMainCtrl->m_stPlayerBaseInfoHash[iIndex];

    if (stPlayerBase._ucIsInited != 1)
    {
        return AnsClients(ERROR_NOT_INITED);
    }

    iIndex = pstMainCtrl->m_stPlayerDetailEx1InfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no detail ex1 data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerDetailInfoEx1& stPlayerDetailEx1 = pstMainCtrl->m_stPlayerDetailEx1InfoHash[iIndex];
        
    iIndex = pstMainCtrl->m_stPlayerOnlineDataHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no online data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerOnlineData& stPlayerOnline =  pstMainCtrl->m_stPlayerOnlineDataHash[iIndex];
    

    if (!pstMainCtrl->m_stCommConfigLoader.IsOpen(SYS_OPEN_COND_ID_55, stPlayerBase, stPlayerOnline))
    {
        return AnsClients(ERROR_SYS_NOT_OPEN);
    }

    stAns.set_opt(stReq.opt());

    bool bSaveEx1Data = false;
    bool bSaveBaseData = false;

    switch (stReq.opt())
    {
    case 1: //查询信息
        {
            pstMainCtrl->m_stActMgr.GetFightForBoxInfo(stPlayerDetailEx1._stFightForBox, stAns);
        }
        break;
    case 2: //开宝箱
        {
            iRet = pstMainCtrl->m_stActMgr.OpenFightForBox(stPlayerDetailEx1._stFightForBox, uiGID, stReq.box_id(), stAns);

            if (RET_OK == iRet)
            {
                bSaveEx1Data = true;
            }
        }
        break;
    case 3: //3慧眼
        {
            iRet = pstMainCtrl->m_stActMgr.LookFightForBox(stPlayerDetailEx1._stFightForBox, stReq.box_id(), stAns);

            if (RET_OK == iRet)
            {
                bSaveEx1Data = true;
            }
        }
        break;
    case 4: //4购买慧眼
        {
            iRet = pstMainCtrl->m_stActMgr.FightForBoxBuyEye(stPlayerDetailEx1._stFightForBox, stPlayerBase, stAns);

            if (RET_OK == iRet)
            {
                bSaveEx1Data = true;
                bSaveBaseData = true;
            }
        }
        break;
    case 5: //5兑换奖励
        {
            iRet = pstMainCtrl->m_stActMgr.GetFightForBoxBonus(stPlayerDetailEx1._stFightForBox, uiGID, 
                    stReq.box_id(), stReq.box_id() == 100, stAns);

            if (RET_OK == iRet)
            {
                bSaveEx1Data = true;
            }
        }
        break;
    default:
        iRet = RET_SYS_ERROR;
        break;
    }

    if (bSaveBaseData)
    {
        CVarObjectKey stKey;
        stKey.m_chDataType = DT_PLAYER_BASE_INFO;
        stKey.m_u64ID = stPlayerBase._uiGID;
        CMainCtrl::m_pstMain->UpdateData(stKey, stPlayerBase, VOP_UPDATE);
    }

    if (bSaveEx1Data)
    {
        CVarObjectKey stKey;
        stKey.m_chDataType = DT_PLAYER_DETAIL_EX1_INFO;
        stKey.m_u64ID = stPlayerDetailEx1._uiGID;
        CMainCtrl::m_pstMain->UpdateData(stKey, stPlayerDetailEx1, VOP_UPDATE);
    }
    
    stAns.set_is_start(stPlayerDetailEx1._stFightForBox._ucHasBegin);
    return AnsClients(iRet);
}

int CCmdFightForBox::AnsClients(int iRet)
{
    stMsgHead.set_msgret(iRet);
    stMsgHead.set_msgtype(CSMsgDef::EMT_ANSWER);

    if (iRet != RET_OK)
    {
        pstMainCtrl->ReturnMsgHead(stMsgHead, stEnpHead);
        return Done(iRet);
    }

    pstMainCtrl->m_stEncodeBuf.Clear();
    pstMainCtrl->EncodePBMsg(stMsgHead, pstMainCtrl->m_stEncodeBuf);
    pstMainCtrl->EncodePBMsg(stAns, pstMainCtrl->m_stEncodeBuf);
    if (pstMainCtrl->AnswerToClient(stEnpHead, pstMainCtrl->m_stEncodeBuf,
        true))
    {
        CT_WARNING((""));
        return Done(RET_SYS_ERROR);
    }

    return Done(iRet);
}

//////////////////////开服特卖////////////////////////////////////////////////////
CT_REGISTER_ASYNCCMD(ID_MAIN_NEWZONE_SALES, CCmdNewZoneSales);
int CCmdNewZoneSales::Do(void* pData)
{
    CT_ASSERT(pData);

    //解析消息
    CCmdPBDoParam* pstParam = (CCmdPBDoParam*) pData;
    pstMainCtrl = (CMainCtrl*) pstParam->m_pMain;

    if (pstParam->m_pstMsgHead->msgid() != ID_MAIN_NEWZONE_SALES||
        pstParam->m_pstMsgHead->msgtype() != CSMsgDef::EMT_REQUEST)
    {
        CT_ERROR(("Cmd Stat Err Cmd=%d CmdID=%d Tpye=%d",
            ID_MAIN_FIGHT_FOR_BOX,
            pstParam->m_pstMsgHead->msgid(),
            pstParam->m_pstMsgHead->msgtype()));
        return Done(RET_SYS_ERROR);
    }

    stMsgHead = *(pstParam->m_pstMsgHead);
    stEnpHead = *(pstParam->m_pstEnpHead);
    int iRet = pstMainCtrl->DecodePBMsg(stReq, pstParam);
    if (iRet)
    {
        return AnsClients(iRet);
    }
    //消息解析结束

    uiGID = stReq.gid();
  
    //检查登录
    iRet = pstMainCtrl->CheckLogin(uiGID, stEnpHead);
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    LogicDo(RET_OK);
    return RET_OK;
}

int CCmdNewZoneSales::LogicDo(int iRet)
{
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    int iIndex = 0;

    PREPARE_PLAYER_BASE_INFO(this, uiGID);
    ASSERT_PLAYER_PREPARED(uiGID);

    PREPARE_PLAYER_DETAIL_EX1_INFO(this, uiGID);
    ASSERT_PLAYER_DETAIL_EX1_INFO(uiGID);

    PREPARE_PLAYER_ONLINE_DATA(this, uiGID);
    ASSERT_PLAYER_ONLINE_DATA_PREPARED(uiGID);    

    iIndex = pstMainCtrl->m_stPlayerBaseInfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no base data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerBaseInfo& stPlayerBase = pstMainCtrl->m_stPlayerBaseInfoHash[iIndex];

    if (stPlayerBase._ucIsInited != 1)
    {
        return AnsClients(ERROR_NOT_INITED);
    }

    iIndex = pstMainCtrl->m_stPlayerDetailEx1InfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no detail ex1 data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerDetailInfoEx1& stPlayerDetailEx1 = pstMainCtrl->m_stPlayerDetailEx1InfoHash[iIndex];

    iIndex = pstMainCtrl->m_stPlayerOnlineDataHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no online data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerOnlineData& stPlayerOnline =  pstMainCtrl->m_stPlayerOnlineDataHash[iIndex];


    iRet = CheckSysOpen(stPlayerBase, stPlayerOnline);
    if (iRet)
    {
        return AnsClients(iRet);
    }
        
    bool bSaveEx1Data = false;
    bool bSaveBaseData = false;

    CDropItem stDropItem;
    stDropItem.SetOssModule(OSS_MODULE_NEWSALES);

    unsigned int uiNotifyType = 0;
    switch (stReq.opt())
    {
    case 1:
        {
            pstMainCtrl->m_stActMgr.GetNewZoneSalesInfo(stPlayerDetailEx1._stNewSales, stAns);
        }
        break;

    case 2:
        {
            iRet = pstMainCtrl->m_stActMgr.BuyNewSalesItem (stPlayerBase, stPlayerDetailEx1._stNewSales, stReq.pos(), stDropItem);
            if (RET_OK == iRet)
            {
                bSaveBaseData = true;
                bSaveEx1Data = true;
                
                uiNotifyType =  NOTIFY_USER_MONEY;
            }
        }
        break;

    case 3:
        {
            iRet = pstMainCtrl->m_stActMgr.BuyNewSalesItemAll (stPlayerBase, stPlayerDetailEx1._stNewSales, stDropItem);
            if (RET_OK == iRet)
            {
                bSaveBaseData = true;
                bSaveEx1Data = true;

                uiNotifyType =  NOTIFY_USER_MONEY;
            }  
        }
        break;

    case 4:
        {
            iRet = pstMainCtrl->m_stActMgr.GetNewSalesBonus (stPlayerBase, stPlayerDetailEx1._stNewSales, stDropItem);
            if (RET_OK == iRet)
            {  
                bSaveBaseData = true;
                bSaveEx1Data = true;
                                
                pstMainCtrl->m_stActMgr.NotifyActListToSelf (uiGID);
            }  
        }
        break;

    default:
        iRet = ERROR_SYS_NOT_OPEN;
        break;
    }

    if (bSaveBaseData)
    {
        CVarObjectKey stKey;
        stKey.m_chDataType = DT_PLAYER_BASE_INFO;
        stKey.m_u64ID = stPlayerBase._uiGID;
        CMainCtrl::m_pstMain->UpdateData(stKey, stPlayerBase, VOP_UPDATE);
    }

    if (bSaveEx1Data)
    {
        CVarObjectKey stKey;
        stKey.m_chDataType = DT_PLAYER_DETAIL_EX1_INFO;
        stKey.m_u64ID = stPlayerDetailEx1._uiGID;
        CMainCtrl::m_pstMain->UpdateData(stKey, stPlayerDetailEx1, VOP_UPDATE);
    }

    pstMainCtrl->m_stNotifyMgr.Notify(uiGID, uiNotifyType);
    if (CT_BIT_TEST(stPlayerBase._uiActStatus, ACT_BIT_NEWSALES2))
    {
        stAns.set_can_get_bonus(true);
    }

    stDropItem.GetPBMsg(uiGID, *(stAns.mutable_gained_items()));
    return AnsClients(iRet);
}

int CCmdNewZoneSales::AnsClients(int iRet)
{
    stMsgHead.set_msgret(iRet);
    stMsgHead.set_msgtype(CSMsgDef::EMT_ANSWER);

    if (iRet != RET_OK)
    {
        pstMainCtrl->ReturnMsgHead(stMsgHead, stEnpHead);
        return Done(iRet);
    }

    stAns.set_opt(stReq.opt());
    stAns.set_pos(stReq.pos());
    pstMainCtrl->m_stEncodeBuf.Clear();
    pstMainCtrl->EncodePBMsg(stMsgHead, pstMainCtrl->m_stEncodeBuf);
    pstMainCtrl->EncodePBMsg(stAns, pstMainCtrl->m_stEncodeBuf);
    if (pstMainCtrl->AnswerToClient(stEnpHead, pstMainCtrl->m_stEncodeBuf,
        true))
    {
        CT_WARNING((""));
        return Done(RET_SYS_ERROR);
    }

    return Done(iRet);
}

int CCmdNewZoneSales::CheckSysOpen (CPlayerBaseInfo & stPlayerBase, CPlayerOnlineData& stPlayerOnline)
{
    if (1 != stReq.opt())
    {
        if (false == pstMainCtrl->m_stActMgr.IsNewSalesOpen(stPlayerBase))
        {
            return ERROR_SYS_NOT_OPEN;
        }
    }

    return RET_OK;
}

//////////////////////学院杯////////////////////////////////////////////////////
CT_REGISTER_ASYNCCMD(ID_MAIN_ACA_CUP, CCmdAcaCup);
int CCmdAcaCup::Do(void* pData)
{
    CT_ASSERT(pData);

    //解析消息
    CCmdPBDoParam* pstParam = (CCmdPBDoParam*) pData;
    pstMainCtrl = (CMainCtrl*) pstParam->m_pMain;

    if (pstParam->m_pstMsgHead->msgid() != ID_MAIN_ACA_CUP||
        pstParam->m_pstMsgHead->msgtype() != CSMsgDef::EMT_REQUEST)
    {
        CT_ERROR(("Cmd Stat Err Cmd=%d CmdID=%d Tpye=%d",
            ID_MAIN_ACA_CUP,
            pstParam->m_pstMsgHead->msgid(),
            pstParam->m_pstMsgHead->msgtype()));
        return Done(RET_SYS_ERROR);
    }

    stMsgHead = *(pstParam->m_pstMsgHead);
    stEnpHead = *(pstParam->m_pstEnpHead);
    int iRet = pstMainCtrl->DecodePBMsg(stReq, pstParam);
    if (iRet)
    {
        return AnsClients(iRet);
    }
    //消息解析结束

    uiGID = stReq.gid();

    //检查登录
    iRet = pstMainCtrl->CheckLogin(uiGID, stEnpHead);
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    LogicDo(RET_OK);
    return RET_OK;
}

int CCmdAcaCup::LogicDo(int iRet)
{
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    int iIndex = 0;

    PREPARE_PLAYER_BASE_INFO(this, uiGID);
    ASSERT_PLAYER_PREPARED(uiGID);

    PREPARE_PLAYER_DETAIL_EX1_INFO(this, uiGID);
    ASSERT_PLAYER_DETAIL_EX1_INFO(uiGID);

    PREPARE_PLAYER_ONLINE_DATA(this, uiGID);
    ASSERT_PLAYER_ONLINE_DATA_PREPARED(uiGID);    

    iIndex = pstMainCtrl->m_stPlayerBaseInfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no base data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerBaseInfo& stPlayerBase = pstMainCtrl->m_stPlayerBaseInfoHash[iIndex];

    if (stPlayerBase._ucIsInited != 1)
    {
        return AnsClients(ERROR_NOT_INITED);
    }

    iIndex = pstMainCtrl->m_stPlayerDetailEx1InfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no detail ex1 data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerDetailInfoEx1& stPlayerDetailEx1 = pstMainCtrl->m_stPlayerDetailEx1InfoHash[iIndex];

    /*
    iIndex = pstMainCtrl->m_stPlayerOnlineDataHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no online data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerOnlineData& stPlayerOnline =  pstMainCtrl->m_stPlayerOnlineDataHash[iIndex];
    */

    stAns.set_opt(stReq.opt());

    bool bSaveEx1Data = false;
    bool bSaveBaseData = false;

    switch (stReq.opt())
    {
    case 1: //报名
        {
            iRet = pstMainCtrl->m_stAcaCupMgr.AddRole(uiGID, stPlayerBase._shLevel, stPlayerBase._ucAcademy, stPlayerDetailEx1._stAcaCupUserData);
        
            if (RET_OK == iRet)
            {
                bSaveEx1Data = true;
            }
        }
        break;
    case 2: //获取淘汰赛战报
        {
            pstMainCtrl->m_stAcaCupMgr.GetFirstStatVideoList(uiGID, stAns);
        }
        break;
    case 3: //获取决赛信息
        {
            pstMainCtrl->m_stAcaCupMgr.GetSecondStatInfo(uiGID, stPlayerDetailEx1._stAcaCupUserData, stAns);
        }
        break;
    case 5: //获取支持榜
        {
            pstMainCtrl->m_stAcaCupMgr.GetSupportList(stAns);
        }
        break;
    case 6: //决赛战报
        {
            pstMainCtrl->m_stAcaCupMgr.GetSecondStatVideoList(stReq.dest_gid(), stAns);
        }
        break;
    case 7: //鼓舞
        {
            iIndex = pstMainCtrl->FindPlayerCacheData(stReq.dest_gid());
            if (iIndex < 0)
            {
                CT_ERROR(("gid = %u", stReq.dest_gid()));
                return AnsClients(RET_SYS_ERROR);
            }
            CPlayerCacheData& stPlayerCacheData = pstMainCtrl->m_stPlayerCacheDataHash[iIndex];

            iRet = pstMainCtrl->m_stAcaCupMgr.Inspire(uiGID, stReq.dest_gid(), stPlayerCacheData);

            if (RET_OK == iRet)
            {
                bSaveEx1Data = true;
            }
        }
        break;
    case 8: //竞猜
        {
            iRet = pstMainCtrl->m_stAcaCupMgr.Guess(uiGID, stPlayerBase._shLevel, stPlayerDetailEx1._stAcaCupUserData, stReq.dest_gid());
        
            if (RET_OK == iRet)
            {
                bSaveEx1Data = true;
            }
        }
        break;
    case 9: //获取竞猜结果
        {
            pstMainCtrl->m_stAcaCupMgr.GetGuessList(uiGID, stPlayerDetailEx1._stAcaCupUserData, stAns);
        }
        break;
    default:
        iRet = RET_SYS_ERROR;
        break;
    }

    if (bSaveBaseData)
    {
        CVarObjectKey stKey;
        stKey.m_chDataType = DT_PLAYER_BASE_INFO;
        stKey.m_u64ID = stPlayerBase._uiGID;
        CMainCtrl::m_pstMain->UpdateData(stKey, stPlayerBase, VOP_UPDATE);
    }

    if (bSaveEx1Data)
    {
        CVarObjectKey stKey;
        stKey.m_chDataType = DT_PLAYER_DETAIL_EX1_INFO;
        stKey.m_u64ID = stPlayerDetailEx1._uiGID;
        CMainCtrl::m_pstMain->UpdateData(stKey, stPlayerDetailEx1, VOP_UPDATE);
    }

    return AnsClients(iRet);
}

int CCmdAcaCup::AnsClients(int iRet)
{
    stMsgHead.set_msgret(iRet);
    stMsgHead.set_msgtype(CSMsgDef::EMT_ANSWER);

    if (iRet != RET_OK)
    {
        pstMainCtrl->ReturnMsgHead(stMsgHead, stEnpHead);
        return Done(iRet);
    }

    pstMainCtrl->m_stEncodeBuf.Clear();
    pstMainCtrl->EncodePBMsg(stMsgHead, pstMainCtrl->m_stEncodeBuf);
    pstMainCtrl->EncodePBMsg(stAns, pstMainCtrl->m_stEncodeBuf);
    if (pstMainCtrl->AnswerToClient(stEnpHead, pstMainCtrl->m_stEncodeBuf,
        true))
    {
        CT_WARNING((""));
        return Done(RET_SYS_ERROR);
    }

    return Done(iRet);
}

//////////////////////领地战////////////////////////////////////////////////////
CT_REGISTER_ASYNCCMD(ID_MAIN_MANOR_BATTLE, CCmdManorBattle);
int CCmdManorBattle::Do(void* pData)
{
    CT_ASSERT(pData);

    //解析消息
    CCmdPBDoParam* pstParam = (CCmdPBDoParam*) pData;
    pstMainCtrl = (CMainCtrl*) pstParam->m_pMain;

    if (pstParam->m_pstMsgHead->msgid() != ID_MAIN_MANOR_BATTLE ||
        pstParam->m_pstMsgHead->msgtype() != CSMsgDef::EMT_REQUEST)
    {
        CT_ERROR(("Cmd Stat Err Cmd=%d CmdID=%d Tpye=%d",
            ID_MAIN_MANOR_BATTLE,
            pstParam->m_pstMsgHead->msgid(),
            pstParam->m_pstMsgHead->msgtype()));
        return Done(RET_SYS_ERROR);
    }

    stMsgHead = *(pstParam->m_pstMsgHead);
    stEnpHead = *(pstParam->m_pstEnpHead);
    int iRet = pstMainCtrl->DecodePBMsg(stReq, pstParam);
    if (iRet)
    {
        return AnsClients(iRet);
    }
    //消息解析结束

    _iSubCmd = stReq.sub_type();
    _uiGID = stReq.gid();
    _uiObjGID = 0;
    _stInfo.Clear();

    //检查登录
    iRet = pstMainCtrl->CheckLogin(_uiGID, stEnpHead);
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    stAns.set_gid((int)_uiGID);
    stAns.set_sub_type(_iSubCmd);

    LogicDo(RET_OK);
    return RET_OK;
}

int CCmdManorBattle::LogicDo(int iRet)
{
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    int iIndex = 0;

    PREPARE_PLAYER_BASE_INFO(this, _uiGID);
    ASSERT_PLAYER_PREPARED(_uiGID);

    PREPARE_PLAYER_DETAIL_INFO(this, _uiGID);
    ASSERT_PLAYER_DETAIL_PREPARED(_uiGID);

    PREPARE_PLAYER_ONLINE_DATA(this, _uiGID);
    ASSERT_PLAYER_ONLINE_DATA_PREPARED(_uiGID);

    iIndex = pstMainCtrl->m_stPlayerBaseInfoHash.HashFind(_uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no base data user(%u)", _uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerBaseInfo& stPlayerBase = pstMainCtrl->m_stPlayerBaseInfoHash[iIndex];

    if (stPlayerBase._ucIsInited != 1)
    {
        return AnsClients(ERROR_NOT_INITED);
    }

    iIndex = pstMainCtrl->m_stPlayerDetailInfoHash.HashFind(_uiGID);
    if (iIndex < 0)
	{
        CT_ERROR(("no detail data user(%u)", _uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
	}
	CPlayerDetailInfo& stPlayerDetail =
        pstMainCtrl->m_stPlayerDetailInfoHash[iIndex];

    iIndex = pstMainCtrl->m_stPlayerOnlineDataHash.HashFind(_uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no online data user(%u)", _uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerOnlineData& stPlayerOnline =
        pstMainCtrl->m_stPlayerOnlineDataHash[iIndex];

    iIndex = pstMainCtrl->FindPlayerCacheData(_uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no cache data user %u", _uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
	CPlayerCacheData& stPlayerCache =
        pstMainCtrl->m_stPlayerCacheDataHash[iIndex];

	switch (_iSubCmd)
	{
    case CManorBattleMgr::CMD_MANOR_BATTLE_SUB_INFO:
        {
            iRet = pstMainCtrl->m_stManorBattleMgr.GetInfo(stPlayerDetail,
                stPlayerCache, stAns);
        }
        break;
    case CManorBattleMgr::CMD_MANOR_BATTLE_SUB_TARGET:
        {
            iRet = pstMainCtrl->m_stManorBattleMgr.GetTargetList(stPlayerBase,
                stPlayerDetail, stPlayerCache, _stInfo, stAns);
        }
        break;
    case CManorBattleMgr::CMD_MANOR_BATTLE_SUB_BATTLE:
        {
            if (!stReq.has_obj_gid())
            {
                return AnsClients(RET_REQ_NOT_COMPLETE);
            }

            iRet = pstMainCtrl->m_stManorBattleMgr.CheckManorBattle(
                stPlayerCache);
            if (iRet)
            {
                return AnsClients(iRet);
            }

            //领地战战斗规则：
            //1 判断发起方的阵营 防守方不攻击城门怪 进攻方可攻击城门怪
            //  如果目标GID已死(不在列表内) 则攻击第一个目标 否则攻击指定目标
            //2 如果是防守方 且进攻列表空 则退出
            //3 如果是进攻方 防守列表空时可以攻击城门怪

            _uiObjGID = stReq.obj_gid();
            int iCamp = pstMainCtrl->m_stManorBattleMgr.GetClanCamp(
                    stPlayerDetail._stUserClan._uiClanId);
            if (ENM_MANOR_BATTLE_CAMP_DEFEND == iCamp)
            {
                if (!pstMainCtrl->m_stManorBattleMgr.IsAttackListGID(_uiObjGID))
                {
                    if (pstMainCtrl->m_stManorBattleMgr.GetAttackListSize()<=0)
                    {
                        return AnsClients(ERROR_MANOR_BATTLE_NO_TARGET);
                    }
                    else
                    {
                        CManorBattleAtkTag& stAtkTag =
                            pstMainCtrl->m_stManorBattleMgr.GetAttackTag(0);
                        _uiObjGID = stAtkTag.GetGID();
                    }
                }
            }
            else if (ENM_MANOR_BATTLE_CAMP_ATTACK == iCamp)
            {
                if (!pstMainCtrl->m_stManorBattleMgr.IsDefendListGID(_uiObjGID))
                {
                    if (pstMainCtrl->m_stManorBattleMgr.GetDefendListSize()<=0)
                    {
                        _uiObjGID = 0;  //表示攻击城门怪
                    }
                    else
                    {
                        CManorBattleDefTag& stDefTag =
                            pstMainCtrl->m_stManorBattleMgr.GetDefendTag(0);
                        _uiObjGID = stDefTag.GetGID();
                    }
                }
            }
            else
            {
                return AnsClients(ERROR_MANOR_BATTLE_NOT_IN_LIST);
            }

            MsgAnsManorBattle stObjAns;

            if (_uiObjGID > 0)  //攻击指定目标
            {
                PREPARE_PLAYER_BASE_INFO(this, _uiObjGID);
                ASSERT_PLAYER_PREPARED(_uiObjGID);
                
                PREPARE_PLAYER_DETAIL_INFO(this, _uiObjGID);
                ASSERT_PLAYER_DETAIL_PREPARED(_uiObjGID);
                
                PREPARE_PLAYER_ONLINE_DATA(this, _uiObjGID);
                ASSERT_PLAYER_ONLINE_DATA_PREPARED(_uiObjGID);
                
                iIndex = pstMainCtrl->m_stPlayerBaseInfoHash.HashFind(
                    _uiObjGID);
                if (iIndex < 0)
                {
                    CT_ERROR(("no base data user(%u)", _uiObjGID));
                    return AnsClients(RET_SYSTEM_FAIL);
                }
                CPlayerBaseInfo& stPlayerBaseB =
                    pstMainCtrl->m_stPlayerBaseInfoHash[iIndex];
                
                iIndex = pstMainCtrl->m_stPlayerDetailInfoHash.HashFind(
                    _uiObjGID);
                if (iIndex < 0)
                {
                    CT_ERROR(("no detail data user(%u)", _uiObjGID));
                    return AnsClients(RET_SYSTEM_FAIL);
                }
                CPlayerDetailInfo& stPlayerDetailB =
                    pstMainCtrl->m_stPlayerDetailInfoHash[iIndex];
                
                iIndex = pstMainCtrl->m_stPlayerOnlineDataHash.HashFind(
                    _uiObjGID);
                if (iIndex < 0)
                {
                    CT_ERROR(("no online data user(%u)", _uiObjGID));
                    return AnsClients(RET_SYSTEM_FAIL);
                }
                CPlayerOnlineData& stPlayerOnlineB =
                    pstMainCtrl->m_stPlayerOnlineDataHash[iIndex];
                
                iIndex = pstMainCtrl->FindPlayerCacheData(_uiObjGID);
                if (iIndex < 0)
                {
                    CT_ERROR(("no cache data user %u", _uiObjGID));
                    return AnsClients(RET_SYSTEM_FAIL);
                }
                CPlayerCacheData& stPlayerCacheB =
                    pstMainCtrl->m_stPlayerCacheDataHash[iIndex];

                stObjAns.set_gid(stPlayerDetailB._uiGID);
                stObjAns.set_sub_type(
                    CManorBattleMgr::CMD_MANOR_BATTLE_SUB_BATTLE);

                pstMainCtrl->m_stManorBattleMgr.GetCommInfo(stPlayerDetail,
                    stAns);

                pstMainCtrl->m_stManorBattleMgr.GetCommInfo(stPlayerDetailB,
                    stObjAns);

                iRet = pstMainCtrl->m_stManorBattleMgr.ManorBattle(stPlayerBase,
                    stPlayerDetail, stPlayerOnline, stPlayerCache,
                    stPlayerBaseB, stPlayerDetailB, stPlayerOnlineB,
                    stPlayerCacheB, _stInfo, true, iCamp, stReq, stAns,
                    stObjAns);

                pstMainCtrl->NotifyOnlineUser(stPlayerDetailB._uiGID,
                    ID_MAIN_MANOR_BATTLE, stObjAns, false);
            }
            else    //攻击城门怪
            {
                pstMainCtrl->m_stManorBattleMgr.GetCommInfo(stPlayerDetail,
                    stAns);

                iRet = pstMainCtrl->m_stManorBattleMgr.ManorBattle(stPlayerBase,
                    stPlayerDetail, stPlayerOnline, stPlayerCache, stPlayerBase,
                    stPlayerDetail, stPlayerOnline, stPlayerCache, _stInfo,
                    false, iCamp, stReq, stAns, stObjAns);
            }
        }
        break;
    case CManorBattleMgr::CMD_MANOR_BATTLE_SUB_REVIVE:
        {
            iRet = pstMainCtrl->m_stManorBattleMgr.DeadRevive(stPlayerBase,
                stPlayerDetail, stPlayerCache, _stInfo, stAns);
        }
        break;
    case CManorBattleMgr::CMD_MANOR_BATTLE_SUB_MAP_SHOW:
        {
            iRet = pstMainCtrl->m_stManorBattleMgr.GetMapShow(stAns);
        }
        break;
    case CManorBattleMgr::CMD_MANOR_BATTLE_SUB_LEAVE:
        {
            iRet = pstMainCtrl->m_stManorBattleMgr.LeaveTargetList(
                stPlayerDetail, _stInfo, stAns);
        }
        break;
	default:
		iRet = ERROR_MAIN_SUB_CMD;
		break;
	}

    if (iRet)
    {
        CT_TRACE(("user(gid=%u) manor battle op(sub=%d) error(%d)",
            _uiGID, _iSubCmd, iRet));
        return AnsClients(iRet);
    }

    return AnsClients(RET_OK);
}

int CCmdManorBattle::AnsClients(int iRet)
{
    stMsgHead.set_msgret(iRet);
    stMsgHead.set_msgtype(CSMsgDef::EMT_ANSWER);

    if (iRet != RET_OK)
    {
        pstMainCtrl->ReturnMsgHead(stMsgHead, stEnpHead);
        return Done(iRet);
    }

    pstMainCtrl->m_stEncodeBuf.Clear();
    pstMainCtrl->EncodePBMsg(stMsgHead, pstMainCtrl->m_stEncodeBuf);
    pstMainCtrl->EncodePBMsg(stAns, pstMainCtrl->m_stEncodeBuf);
    if (pstMainCtrl->AnswerToClient(stEnpHead, pstMainCtrl->m_stEncodeBuf,
            true))
    {
        CT_WARNING((""));
        return Done(RET_SYS_ERROR);
    }

    for (int i = 0; i < _stInfo.GetUnitSize(); ++i)
    {
        CManorBattleUnit& stUnit = _stInfo.GetUnit(i);
        if (CManorBattleMgr::CMD_MANOR_BATTLE_SUB_TARGET == stUnit._iSubCmd)
        {
            pstMainCtrl->m_stManorBattleMgr.NotifyTargetList(
                stUnit._iTargetCamp);
        }
        else if (CManorBattleMgr::CMD_MANOR_BATTLE_SUB_TIME_OVER ==
                    stUnit._iSubCmd)
        {
            pstMainCtrl->m_stActMgr.SetActClose(ACT_ID_MANOR_BATTLE);
        }
        else
        {
            pstMainCtrl->m_stManorBattleMgr.NotifyAllSceneRole(stUnit);
        }
    }

    return Done(iRet);
}

//////////////////////奖励找回////////////////////////////////////////////////////
CT_REGISTER_ASYNCCMD(ID_MAIN_REWARD_BACK, CCmdRewardBack);
int CCmdRewardBack::Do(void* pData)
{
    CT_ASSERT(pData);

    //解析消息
    CCmdPBDoParam* pstParam = (CCmdPBDoParam*) pData;
    pstMainCtrl = (CMainCtrl*) pstParam->m_pMain;

    if (pstParam->m_pstMsgHead->msgid() != ID_MAIN_REWARD_BACK ||
        pstParam->m_pstMsgHead->msgtype() != CSMsgDef::EMT_REQUEST)
    {
        CT_ERROR(("Cmd Stat Err Cmd=%d CmdID=%d Tpye=%d",
            ID_MAIN_REWARD_BACK,
            pstParam->m_pstMsgHead->msgid(),
            pstParam->m_pstMsgHead->msgtype()));
        return Done(RET_SYS_ERROR);
    }

    stMsgHead = *(pstParam->m_pstMsgHead);
    stEnpHead = *(pstParam->m_pstEnpHead);
    int iRet = pstMainCtrl->DecodePBMsg(stReq, pstParam);
    if (iRet)
    {
        return AnsClients(iRet);
    }
    //消息解析结束

    iSubCmd = stReq.sub_type();
    uiGID = stReq.gid();

    //检查登录
    iRet = pstMainCtrl->CheckLogin(uiGID, stEnpHead);
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    stAns.set_gid((int)uiGID);
    stAns.set_sub_type(iSubCmd);

    LogicDo(RET_OK);
    return RET_OK;
}

int CCmdRewardBack::LogicDo(int iRet)
{
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    int iIndex = 0;

    PREPARE_PLAYER_BASE_INFO(this, uiGID);
    ASSERT_PLAYER_PREPARED(uiGID);

    PREPARE_PLAYER_DETAIL_INFO(this, uiGID);
    ASSERT_PLAYER_DETAIL_PREPARED(uiGID);

    PREPARE_PLAYER_DETAIL_EX1_INFO(this, uiGID);
    ASSERT_PLAYER_DETAIL_EX1_INFO(uiGID);

    PREPARE_PLAYER_ONLINE_DATA(this, uiGID);
    ASSERT_PLAYER_ONLINE_DATA_PREPARED(uiGID);

    iIndex = pstMainCtrl->m_stPlayerBaseInfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no base data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerBaseInfo& stPlayerBase = pstMainCtrl->m_stPlayerBaseInfoHash[iIndex];

    if (stPlayerBase._ucIsInited != 1)
    {
        return AnsClients(ERROR_NOT_INITED);
    }

    iIndex = pstMainCtrl->m_stPlayerDetailInfoHash.HashFind(uiGID);
    if (iIndex < 0)
	{
        CT_ERROR(("no detail data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
	}
	CPlayerDetailInfo& stPlayerDetail =
        pstMainCtrl->m_stPlayerDetailInfoHash[iIndex];

    iIndex = pstMainCtrl->m_stPlayerDetailEx1InfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no detail ex1 data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerDetailInfoEx1& stPlayerDetailEx1 =
        pstMainCtrl->m_stPlayerDetailEx1InfoHash[iIndex];

    iIndex = pstMainCtrl->m_stPlayerOnlineDataHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no online data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerOnlineData& stPlayerOnline =
        pstMainCtrl->m_stPlayerOnlineDataHash[iIndex];

    //检查系统是否开启
    if (!CMainCtrl::m_pstMain->m_stCommConfigLoader.IsOpen(SYS_OPEN_COND_ID_33,
            stPlayerBase, stPlayerOnline))
    {
        return AnsClients(ERROR_SYS_NOT_OPEN);
    }

	switch (iSubCmd)
	{
    case CRewardBackMgr::CMD_REWARD_BACK_SUB_GET_INFO: //获取信息
        {
            iRet = pstMainCtrl->m_stRewardBackMgr.GetInfo(stPlayerBase,
                stPlayerDetailEx1, stAns);
        }
        break;

    case CRewardBackMgr::CMD_REWARD_BACK_SUB_FREE_BACK: //免费找回
        {
            iRet = pstMainCtrl->m_stRewardBackMgr.FreeBack(stPlayerBase,
                stPlayerDetailEx1, stAns);
        }
        break;

    case CRewardBackMgr::CMD_REWARD_BACK_SUB_GOLD_BACK: //符石找回
        {
            iRet = pstMainCtrl->m_stRewardBackMgr.GoldBack(stPlayerBase,
                stPlayerDetail, stPlayerDetailEx1, stPlayerOnline, stAns);
        }
        break;

	default:
		iRet = ERROR_MAIN_SUB_CMD;
		break;
	}

    if (iRet)
    {
        CT_TRACE(("user(gid=%u) deal reward back op(sub=%d) error(%d)",
            uiGID, iSubCmd, iRet));
        return AnsClients(iRet);
    }

    return AnsClients(RET_OK);
}

int CCmdRewardBack::AnsClients(int iRet)
{
    stMsgHead.set_msgret(iRet);
    stMsgHead.set_msgtype(CSMsgDef::EMT_ANSWER);

    if (iRet != RET_OK)
    {
        pstMainCtrl->ReturnMsgHead(stMsgHead, stEnpHead);
        return Done(iRet);
    }

    pstMainCtrl->m_stEncodeBuf.Clear();
    pstMainCtrl->EncodePBMsg(stMsgHead, pstMainCtrl->m_stEncodeBuf);
    pstMainCtrl->EncodePBMsg(stAns, pstMainCtrl->m_stEncodeBuf);
    if (pstMainCtrl->AnswerToClient(stEnpHead, pstMainCtrl->m_stEncodeBuf,
            true))
    {
        CT_WARNING((""));
        return Done(RET_SYS_ERROR);
    }

    return Done(iRet);
}

//////////////////////登录奖励////////////////////////////////////////////////////
CT_REGISTER_ASYNCCMD(ID_MAIN_LOGIN_REWARD, CCmdLoginReward);
int CCmdLoginReward::Do(void* pData)
{
    CT_ASSERT(pData);

    //解析消息
    CCmdPBDoParam* pstParam = (CCmdPBDoParam*) pData;
    pstMainCtrl = (CMainCtrl*) pstParam->m_pMain;

    if (pstParam->m_pstMsgHead->msgid() != ID_MAIN_LOGIN_REWARD ||
        pstParam->m_pstMsgHead->msgtype() != CSMsgDef::EMT_REQUEST)
    {
        CT_ERROR(("Cmd Stat Err Cmd=%d CmdID=%d Tpye=%d",
            ID_MAIN_LOGIN_REWARD,
            pstParam->m_pstMsgHead->msgid(),
            pstParam->m_pstMsgHead->msgtype()));
        return Done(RET_SYS_ERROR);
    }

    stMsgHead = *(pstParam->m_pstMsgHead);
    stEnpHead = *(pstParam->m_pstEnpHead);
    int iRet = pstMainCtrl->DecodePBMsg(stReq, pstParam);
    if (iRet)
    {
        return AnsClients(iRet);
    }
    //消息解析结束

    iSubCmd = stReq.req_type();
    uiGID = stReq.gid();

    //检查登录
    iRet = pstMainCtrl->CheckLogin(uiGID, stEnpHead);
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    stAns.set_gid((int)uiGID);
    stAns.set_req_type(iSubCmd);

    LogicDo(RET_OK);
    return RET_OK;
}

int CCmdLoginReward::LogicDo(int iRet)
{
    if (iRet != RET_OK)
    {
        return AnsClients(iRet);
    }

    int iIndex = 0;

    PREPARE_PLAYER_BASE_INFO(this, uiGID);
    ASSERT_PLAYER_PREPARED(uiGID);

    PREPARE_PLAYER_DETAIL_EX1_INFO(this, uiGID);
    ASSERT_PLAYER_DETAIL_EX1_INFO(uiGID);

    PREPARE_PLAYER_ONLINE_DATA(this, uiGID);
    ASSERT_PLAYER_ONLINE_DATA_PREPARED(uiGID);

    iIndex = pstMainCtrl->m_stPlayerBaseInfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no base data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerBaseInfo& stPlayerBase = pstMainCtrl->m_stPlayerBaseInfoHash[iIndex];

    if (stPlayerBase._ucIsInited != 1)
    {
        return AnsClients(ERROR_NOT_INITED);
    }

    iIndex = pstMainCtrl->m_stPlayerDetailEx1InfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no detail ex1 data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerDetailInfoEx1& stPlayerDetailEx1 =
        pstMainCtrl->m_stPlayerDetailEx1InfoHash[iIndex];

    iIndex = pstMainCtrl->m_stPlayerOnlineDataHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no online data user(%u)", uiGID));
        return AnsClients(RET_SYSTEM_FAIL);
    }
    CPlayerOnlineData& stPlayerOnline =
        pstMainCtrl->m_stPlayerOnlineDataHash[iIndex];

	switch (iSubCmd)
	{
    case CLoginRewardMgr::CMD_LOGIN_REWARD_SUB_INFO: //获取信息
        {
            iRet = pstMainCtrl->m_stLoginRewardMgr.GetInfo(stPlayerDetailEx1,
                stAns);
        }
        break;

    case CLoginRewardMgr::CMD_LOGIN_REWARD_SUB_AWARD: //领取奖励
        {
            iRet = pstMainCtrl->m_stLoginRewardMgr.GetAward(stPlayerDetailEx1,
                stPlayerOnline, stReq, stAns);
        }
        break;

	default:
		iRet = ERROR_MAIN_SUB_CMD;
		break;
	}

    if (iRet)
    {
        CT_TRACE(("user(gid=%u) deal login reward op(sub=%d) error(%d)",
            uiGID, iSubCmd, iRet));
        return AnsClients(iRet);
    }

    return AnsClients(RET_OK);
}

int CCmdLoginReward::AnsClients(int iRet)
{
    stMsgHead.set_msgret(iRet);
    stMsgHead.set_msgtype(CSMsgDef::EMT_ANSWER);

    if (iRet != RET_OK)
    {
        pstMainCtrl->ReturnMsgHead(stMsgHead, stEnpHead);
        return Done(iRet);
    }

    pstMainCtrl->m_stEncodeBuf.Clear();
    pstMainCtrl->EncodePBMsg(stMsgHead, pstMainCtrl->m_stEncodeBuf);
    pstMainCtrl->EncodePBMsg(stAns, pstMainCtrl->m_stEncodeBuf);
    if (pstMainCtrl->AnswerToClient(stEnpHead, pstMainCtrl->m_stEncodeBuf,
            true))
    {
        CT_WARNING((""));
        return Done(RET_SYS_ERROR);
    }

    return Done(iRet);
}

